Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113248 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 2628 invoked from network); 24 Feb 2021 16:46:57 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 24 Feb 2021 16:46:57 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CBB5E1804B3 for ; Wed, 24 Feb 2021 08:35:40 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-qk1-f194.google.com (mail-qk1-f194.google.com [209.85.222.194]) (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:35:40 -0800 (PST) Received: by mail-qk1-f194.google.com with SMTP id l132so1494360qke.7 for ; Wed, 24 Feb 2021 08:35:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=Wisn3abpgOAauQ7SoAuIILAHF7H+xpgVkqDaGxEvC/Y=; b=HWzijvkPOLQ3jyLjhseeVQNk8t5CTKNNMdWbsKJGrtxQWmryGNSKKBl2alpT3+5Kfo h4mAiOZM2HOrHkxzTRKDZMehZBpNSbTDhrCUJc7WV6XVux1jdTnRdGz0i4V2OhMjLyXZ TYLnpAD3NLRKYR/Uke/6iPPsDiIT0kGbhJmYPYOUZWmBmIsXLIvWl4hMUbL/6dnpu+pI 4NdVnx4rb7hsfT92IqjeGAY7hLby1MvImBDLwXKm6d4YayoFSh/U5jQStcgiHzjjai2i kznGVoyRECLfbdm4p+fYEtTO9Qecs5rwa78vFeOeaeO8nYzaSuursJFGsTXyDD3qetlL Goww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=Wisn3abpgOAauQ7SoAuIILAHF7H+xpgVkqDaGxEvC/Y=; b=dqTdXl16L9yN6gdhhy77O6YFY6mcMiB2Uixm6+hEZE8cugLrm5dCKAQVlGURhr8kbq 7fUBWkEvrHRKNxYboh76MK5nT1AVFAaAJwGsaBQpsgD4tbPmToZbGvdsfPpkFJoGcRtv kiLuMaDvSb0XzRi8YonynrPPXOyAAnhb44MURd0ZlkgUkOq8sbUSBJ5MIh3rLn6zQU3J JNgcXAtMCyhzCti1khBYNKZjQPoX/1SVID2/WA2dJ9lY19oAeXPAOJ8tPVBDhgiH/TO9 UFdhyDEka7tI58GZaQdrFjsTTY4Jykg5RB1mR+TqGS8rjOb0HFjG/s2QCACvyYHVwGjf icZA== X-Gm-Message-State: AOAM530xNbT5OYWLuUx+zDi/H6dMA6OkpesJD7EqvYWHCjh7/cMAWamc 5TkjmgGUhWwWqPB0WAmT/yzGaA== X-Google-Smtp-Source: ABdhPJzdk/K6NSmhX2OOmTsxvwMCc2Rhr1py0+0D6agMiuj7kprA+Q71VNuU/8kqMgDwYhHWPJ+UXA== X-Received: by 2002:a05:620a:a4f:: with SMTP id j15mr30579953qka.419.1614184538043; Wed, 24 Feb 2021 08:35:38 -0800 (PST) Received: from [192.168.1.239] (c-24-98-254-8.hsd1.ga.comcast.net. [24.98.254.8]) by smtp.gmail.com with ESMTPSA id g26sm1592295qtu.10.2021.02.24.08.35.37 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Feb 2021 08:35:37 -0800 (PST) Message-ID: Content-Type: multipart/alternative; boundary="Apple-Mail=_CA4994DF-A45E-4A9C-B687-85C956343116" Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.4\)) Date: Wed, 24 Feb 2021 11:35:37 -0500 In-Reply-To: Cc: PHP internals To: Chase Peeler References: <2664e2ef-b965-407c-90fc-77480846a3ad@www.fastmail.com> <84020328-b623-bca1-0c9c-0f7195e08d23@gmail.com> <8CD7D960-51FA-45FE-B88F-2A18BA768DA4@newclarity.net> X-Mailer: Apple Mail (2.3608.120.23.2.4) Subject: Re: [PHP-DEV] Inline conditional that returns null if falsy From: mike@newclarity.net (Mike Schinkel) --Apple-Mail=_CA4994DF-A45E-4A9C-B687-85C956343116 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Feb 24, 2021, at 11:27 AM, Chase Peeler = wrote: >=20 > On Tue, Feb 23, 2021 at 11:27 PM Mike Schinkel > wrote: > > On Feb 23, 2021, at 2:05 PM, Rowan Tommins > wrote: > >=20 > > 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 > >=20 > >=20 > > 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 = should produce a null: > >=20 > > $items =3D []; > > $itemCount =3D $items ? count($items); > >=20 > > 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. >=20 > 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 explicit in the code is probably a better practice than = saving a few keystrokes. >=20 > 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. And in the case of templating, the distinction between null = vs. false vs. "" would be completely moot. >=20 >=20 > But PHP isn't just a templating language anymore. It is not? If it is not I think a lot of userland PHP developers never = got that decree. > 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. Can you elaborate on those? > I think just dropping the need for a third argument on the existing = ternary operator is a bad idea. >=20 > 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.=20 >=20 > =20 > Repeating code similar to that from the message sent by David = Rodrigues you can see that eliminating the ": null" is less noisy: >=20 >
">...
>
">...
>=20 > 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 to drop the ":null" would be a really nice addition for = templating. >=20 > 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.=20 >=20 > -Mike >=20 > 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 point. >=20 > --=20 > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php = >=20 >=20 >=20 > --=20 > Chase Peeler > chasepeeler@gmail.com --Apple-Mail=_CA4994DF-A45E-4A9C-B687-85C956343116--