Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113246 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 99071 invoked from network); 24 Feb 2021 16:38:35 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 24 Feb 2021 16:38:35 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id EE9001804E2 for ; Wed, 24 Feb 2021 08:27:21 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-vs1-f51.google.com (mail-vs1-f51.google.com [209.85.217.51]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 24 Feb 2021 08:27:21 -0800 (PST) Received: by mail-vs1-f51.google.com with SMTP id a62so1339521vsa.10 for ; Wed, 24 Feb 2021 08:27:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=i2qbfou2mmyB6u2ks8nEboOz5GjLD+Lnzka13JPjZH8=; b=qJiOAI1l9NTE2nzZ9/Qcr4718C96qw8NDrbyyVgovT2vNu8w16hXSQt78+4ugSq/1I oNiNwFE2dUYi4SqlLoathCkR0yDnoxsvOZOrxKtGH7R+dlBoZ9o+f9ISA/cEUEJxqeK+ 6WSZBn/2SvpL9rhWhRnc3aYrMxkkEegg8AgIhElfYgTawQYr4HL1fo35rflgbksrSzsK HlT81/fb6GhUG1vPCVKwmToevLyUrBREOK3mr5lVCZiAyN6pVWdbZhqccCc04vSLWB6x JzN/lrtVU/E7jjK76bvBNuvwnCFZzcqHemUMjPqJ5az2oERKAL8wiV5BJYXcvtatnt7C 0NJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=i2qbfou2mmyB6u2ks8nEboOz5GjLD+Lnzka13JPjZH8=; b=EVejLGklFPZvsAA7loU2CnxJTtefxzQg6joxHVrdno9HaGIL//hB69dFnJH/PEJLqE 8IBaBaJV9l1X6QKPG5N0NiNp+Vhu7Uk2ol+4jGzYS0Kir9wASPSWTVvHPKft+guoGTbA GCb27b8dwOCGly1L39oSlL9VJCXPpUcSetgljlcaRJEyR7Eeb7Wn6V7rd4GnnJPyJBuE 9/zcJ0k8EZNupoL1mVOf3oGsaibDdbbhr96KC7KeCt5vZMFtf5c1nG2J3KhuAFAz0zTo 2omOKWUJ6kxWLax/Z3KBhE019a+cHRhsaLSypdtF5we3F7SO6d7JkYmJu8uvSA8SlJpQ 162g== X-Gm-Message-State: AOAM531G6SkkTFdsj2MuwbkfLjj2efOa96em+IM0RWbawtfBEDGKZaV6 Lk7v8i9Tk5yr9ZRExut7baVbHQ90FNDhd38KdtR4dAYeGQAf9w== X-Google-Smtp-Source: ABdhPJwSNycynHOJBYEXIVlDiThJJc3VAf91i8ADzB+5XnqQYcjoAr+jNK8ByHDPhYkqWjpIou0mw3OHBcCVQpqNJSs= X-Received: by 2002:a67:1046:: with SMTP id 67mr15638509vsq.21.1614184040650; Wed, 24 Feb 2021 08:27:20 -0800 (PST) MIME-Version: 1.0 References: <2664e2ef-b965-407c-90fc-77480846a3ad@www.fastmail.com> <84020328-b623-bca1-0c9c-0f7195e08d23@gmail.com> <8CD7D960-51FA-45FE-B88F-2A18BA768DA4@newclarity.net> In-Reply-To: <8CD7D960-51FA-45FE-B88F-2A18BA768DA4@newclarity.net> Date: Wed, 24 Feb 2021 11:27:09 -0500 Message-ID: To: Mike Schinkel Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000585a5305bc1782b7" Subject: Re: [PHP-DEV] Inline conditional that returns null if falsy From: chasepeeler@gmail.com (Chase Peeler) --000000000000585a5305bc1782b7 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Feb 23, 2021 at 11:27 PM Mike Schinkel wrote: > > On Feb 23, 2021, at 2:05 PM, Rowan Tommins > wrote: > > > > On 23/02/2021 18:41, Albert Casademont wrote: > >> Sure, it's not a big deal having to write the ": null" but it doesn't > add > >> any value > > > > > > On the contrary, it adds an important piece of information: that the > default value is "null", rather than "false", or "0", or "new EmptyValue(= )". > > For instance, it doesn't seem at all obvious to me that this code shoul= d > produce a null: > > > > $items =3D []; > > $itemCount =3D $items ? count($items); > > > > I might be more convinced that "null" is the "natural" value if the > left-hand operand was only checked against null, not "falsiness": in that > case, you can read it as "if it's null, leave it alone". I'd still be > inclined towards "too specific to use up more syntax", though. > > If you look at it from a software engineering perspective =E2=80=94 which= is how I > assume most on this thread have been looking at it =E2=80=94 being more e= xplicit in > the code is probably a better practice than saving a few keystrokes. > > OTOH, if you view it from the perspective of a *templating* language =E2= =80=94 > which is what PHP was initially created to be, for the web =E2=80=94 then= the > reduction in visual noise from omitting ": null" would be a nice plus. An= d > in the case of templating, the distinction between null vs. false vs. "" > would be completely moot. > > But PHP isn't just a templating language anymore. If PHP currently had support for omitting the third argument on the ternary operator, then I'd be against changes that required it given the BC implications. I think just dropping the need for a third argument on the existing ternary operator is a bad idea. I'm ambivalent when it comes to creating a new symbol to support this behavior (e.g. ?!). I don't really think it's necessary, but, I don't think it hurts anything either. > Repeating code similar to that from the message sent by David Rodrigues > you can see that eliminating the ": null" is less noisy: > >
">...
>
">...
> > Although one ":null" eliminated is not that significant, PHP templates > for generating HTML are notorious for having conditionals littered > throughout, with tens if not hundreds of cases per file. So being able t= o > drop the ":null" would be a really nice addition for templating. > > To emphasize this feature address templating use-cases one might argue > that dropping the "or" case of the trinary might only be supported when > between single-line "" delimiters. > > -Mike > > P.S. Of course making it work differently between single-line delimiters > and elsewhere would create inconsistency in the language so I probably > would not actually argue that, I was just trying to make a rhetorical poi= nt. > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > > --=20 Chase Peeler chasepeeler@gmail.com --000000000000585a5305bc1782b7--