Req #76313 [Opn->Sus]: RFE: shorthand for ternary assignment "?="
| From: | requinix@php.net | Date: | Tue, 08 May 2018 16:56:39 +0000 |
| Subject: | Req #76313 [Opn->Sus]: RFE: shorthand for ternary assignment "?=" | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-215162@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=76313&edit=1
ID: 76313
Updated by: requinix@php.net
Reported by: php at richardneill dot org
Summary: RFE: shorthand for ternary assignment "?="
-Status: Open
+Status: Suspended
Type: Feature/Change Request
Package: Variables related
Operating System: Linux
PHP Version: 7.2.5
Block user comment: N
Private report: N
New Comment:
See https://wiki.php.net/rfc/short_ternary_equal_operator
for ?:=
But trying to cram the complete ternary form into a shorthand
$x ?= $y : $z;
looks too confusing.
Previous Comments:
------------------------------------------------------------------------
[2018-05-08 16:48:28] php at richardneill dot org
Description:
------------
In the same way that we can have:
$x += $y;
as a shorthand for:
$x = $x + $y;
it would be helpful if we could have:
$x ?= $y;
as a shorthand for:
$x = $x ?: $y;
Alternatively, we could have the following syntax, which are more aligned with the 2 ways the
ternary operator works, though I think it might less useful:
$x ?:= $y; //c.f. $x = $x ?: $y;
$x ?= $y : $z; //c.f. $x = $x ? $y : $z;
This would be nice to have, simplify quite a lot of typing, and be consistent with all the other
operators such as "*=" and ".=" . Thank you for your consideration and your
time.
A similar request exists here: Bug #72047 though as that bug has been closed, I assume (please
correct me if I'm wrong) that it's better to open a new one. In that bug, the idea is for
"null coalescing", whereas I think it's more useful to deal with anything
"falsey", bearing in mind that many data sources originate as web forms.
Test script:
---------------
<?php
$name1 = "Jane";
$name2 = "";
$name1 ?= "[TBC]";
$name2 ?= "[TBC]";
echo "$name1 and $name2 are attending this event.";
// Jane and [TBC] are attending this event."
?>
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76313&edit=1