Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113243 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 51442 invoked from network); 24 Feb 2021 04:38:23 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 24 Feb 2021 04:38:23 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 6597F1804C3 for ; Tue, 23 Feb 2021 20:27:02 -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=0.0 required=5.0 tests=BAYES_40,DKIM_SIGNED, DKIM_VALID,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 ; Tue, 23 Feb 2021 20:27:01 -0800 (PST) Received: by mail-qk1-f173.google.com with SMTP id b14so1084808qkk.0 for ; Tue, 23 Feb 2021 20:27:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=from:content-transfer-encoding:mime-version:subject:date:references :to:in-reply-to:message-id; bh=0sS+z/q04YCzMxa788u5zsDjG6aGGQ0/fjUPWvL55F8=; b=pqI0qa7wPHXmTDJfiMOdAiudjxUm5xxv06VbxV7NUxE02gnOHxGM9bA6i7nn8JG2qt bOcxTNXtNDJ8lj7y4qBZ2BNQq+TMMFYzVR5KVYtNCYLw6XYABYRmgOSV7cuy7QWvJhDb f+CyvnhT4I6/vyh1mkH4VM5dcVVCRUpwfFTU6ZXUUXsOF8R3OzlPBnWaiZrIThR2YPpw 2HEPuZbYDLUqdg89ovpgU3gu+qIXPAZpikzRz76G9vV51Rc6rs8FhSIk2/7iZIYd0d9S +bgdKHc/kecI8EDczsMhUPtU/z5ch9LmjnhRqyAl+GU1NaEWgvD4Wrdv3WQJinFOq561 YwwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:content-transfer-encoding:mime-version :subject:date:references:to:in-reply-to:message-id; bh=0sS+z/q04YCzMxa788u5zsDjG6aGGQ0/fjUPWvL55F8=; b=KPNMReSV7+91WoAj8ooGUdz36GbWYcF+hbCaEkCAM3+65IeVj9oiKziFy8hOoxP2Fk 9T05O7sUHZPRgzE0DA6bDMxz0DZI3Abr+aey1MdIoAFIpX8GLUCECmmy5deE0NsB3ry+ NM516K+WOxXtr5oEdRhEeMmaLH3zt/EduBn+TH1BCcE8KY0WojmcSZUxAvElWjm+Ycnk AXNq34IvzcJZgOIsp5zvMC8QDVBls5uQsL5cuq2LuPBOtMwAwmueRq9oOgNsO8QH/pEl BYUwNz/2p5Ql9uo2wwF1fWNDsdwg4xZsPyYSFN76IDiHe6nXxYX5ZeWUgSrxfaCyLx8V B10g== X-Gm-Message-State: AOAM530kWUawbE2QuYIqF7EHFDmZBoUuK69N6w7KTI8OCzje1c76ZJ/H SjuoCIMpyZyVHrZaIDTXgqVFH2v8Ng0HKw== X-Google-Smtp-Source: ABdhPJymN4ZdtuglckqCYP7tugMrDVgUjyJgqWJEGPS5C6ZfOultrylIB6bilvOB/kGBZziOGIYJ2Q== X-Received: by 2002:a37:804:: with SMTP id 4mr29836256qki.207.1614140817792; Tue, 23 Feb 2021 20:26:57 -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 19sm686014qkv.95.2021.02.23.20.26.57 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Feb 2021 20:26:57 -0800 (PST) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.4\)) Date: Tue, 23 Feb 2021 23:26:56 -0500 References: <2664e2ef-b965-407c-90fc-77480846a3ad@www.fastmail.com> <84020328-b623-bca1-0c9c-0f7195e08d23@gmail.com> To: PHP internals In-Reply-To: <84020328-b623-bca1-0c9c-0f7195e08d23@gmail.com> Message-ID: <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) > 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. 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. 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. 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 = to 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.=20 -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 = point.