Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113251 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 11802 invoked from network); 24 Feb 2021 17:39:15 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 24 Feb 2021 17:39:15 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id EA044180539 for ; Wed, 24 Feb 2021 09:28:01 -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-f173.google.com (mail-qk1-f173.google.com [209.85.222.173]) (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 09:28:01 -0800 (PST) Received: by mail-qk1-f173.google.com with SMTP id m144so2888955qke.10 for ; Wed, 24 Feb 2021 09:28:01 -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=WZgzCg6PidDaweiasxk45ipDhbsQzXL/V74kEy0h/bM=; b=Ol7SV2PSve8Y148npiUa2mWsYRUigTuNRvFT175fuQfflVvvtF+O/H/I1Rj/untN2L YTSGwktX4Hw/33ss0C4imsYlTaUyLs1oG+ePKgayO9c64YkTxZtk74HL3XH0AqeLCLN+ JC6UeviwSyx3TsoJq6tuZhca8FfLK+uLxR0NmNuPHdMMzZioHkyb3AhEYNpLOWUZW0bN jIH5gKk9tCVZywi/2h9md///URoqToV7ShgOy0Ncrs4VjkruoPY8vouVhzAGlVpSCZrY DrL5jBDnjRuBVOT3k1FTZYsqyTKjPsfsL75lwRgR1pf5YXAQc596JWC9RESyOSu7mXUG WLng== 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=WZgzCg6PidDaweiasxk45ipDhbsQzXL/V74kEy0h/bM=; b=BlpxsYbQTCtz5+c0+ZId6UVONm/g2z/wvSVZAHKJCnspaIDfzaPbLh6x+UIwgKfHbr 3cwqaqjVA0P+US4N5EGways3RLxrAg408PLpxl3aG5Safadb3LyTCH2K0cHLd5M3GOZ3 SpaxIjSjqq87jO9c6sHAyWEnoNvNnaZOGht3KJ517bOeuBi9rekt/nbrg+oIvdIb4Zyk jd62pqbWnWapaXqYrcdf8Qwc7YfBUce29OgkKPYmiqdnfdfj5jDDcwe15M5/fxdIYNDt lSpqhEQxJNhnx+/WLjCNLA1wm0USb+fsnwyW5z3Xy17qb2u5Ax8d8DJNaVUP7lQpV/88 FZdg== X-Gm-Message-State: AOAM532wxB7AHw+l1YO3h0gvsw2g1t0w/3+1fJkMOunzsdAnsrbxpoJv C5LC7pVc2DEK9ggZe63YGndlTQ== X-Google-Smtp-Source: ABdhPJyxevYPTR+ywgZotITk5ZBs/aC5UwlwwvwC6bgV7LU+77Pc8HRmtFmKLObucQk2zTR/D11Kag== X-Received: by 2002:a37:49cd:: with SMTP id w196mr31304551qka.288.1614187680633; Wed, 24 Feb 2021 09:28:00 -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 i5sm1981013qkg.32.2021.02.24.09.27.59 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Feb 2021 09:28:00 -0800 (PST) Message-ID: <37099727-B15D-4B6B-AD04-3E309E350417@newclarity.net> Content-Type: multipart/alternative; boundary="Apple-Mail=_6D1DA2FD-6790-40B3-8C1C-127000255EBE" Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.4\)) Date: Wed, 24 Feb 2021 12:27:59 -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=_6D1DA2FD-6790-40B3-8C1C-127000255EBE Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Feb 24, 2021, at 11:49 AM, Chase Peeler = wrote: >=20 >=20 >=20 > On Wed, Feb 24, 2021 at 11:35 AM Mike Schinkel > wrote: >=20 >> 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. >=20 > It is not? If it is not I think a lot of userland PHP developers = never got that decree. >=20 >=20 > I didn't say it COULDN'T be used for templating It would benefit when PHP *is* used for templating which is still not an = insignificant use of PHP, and this one simple thing would make templates = easier to read. > (although even then I'd suggest utilizing a library like smarty or = twig) A long time ago I read an article on SitePoint that argued that using = templating languages like Smarty or Twig made no sense because PHP *is* = a templating language. =20 That stuck with me and for many (most?) use-cases I still agree with it. > but that it is a lot more than that. I'd also say that, good or bad, = the direction of the language in the last 15+ years has been to make it = a robust language that can be used for more than just templating.=20 I think it is specious to imply allowing $foo ? $bar to return null when = $foo=3D=3Dnil would make PHP a less robust language. > Well it's pretty obvious. If php currently supported a statement like = "$user ? 'online'" then a change that requires the third argument would = break every single instance of code that didn't have one and wouldn't = provide any functional gains as nothing prevents people from adding on = the ": null" if they want to. It's a moot point, though, because PHP = doesn't support it. I just included that statement to give context to my = views - that I'm not automatically in favor of changes just because = they enforce better development practices.=20 So 1.) if PHP allowed "$user ? 'online'" and then 2.) PHP later = disallowed it then 3.) the second action would created BC concerns? Yes, that is a moot point with respect to the proposal posed by this = thread. -Mike= --Apple-Mail=_6D1DA2FD-6790-40B3-8C1C-127000255EBE--