Coalesce assign operator (??=) implemented
| From: | Nikita Popov | Date: | Tue, 22 Jan 2019 10:33:35 +0000 |
| Subject: | Coalesce assign operator (??=) implemented | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-103774@lists.php.net to get a copy of this message | ||
Hi internals,
Some time ago an RFC for the ??= operator has been accepted:
https://wiki.php.net/rfc/null_coalesce_equal_operator
However, due to implementation difficulties, the RFC hasn't landed since
then. I'm happy to say that these difficulties are resolved now, and ??=
has landed with
https://github.com/php/php-src/commit/a50198d0fef652ca052cda642d6e98a9101eb73f
.
To summarize the important ??= semantics: $a ??= $b is roughly equivalent
to $a ?? ($a = $b). In $a[foo()] ??= bar() the function foo() will be
evaluated exactly once, and bar() will be evaluated iff $a[foo()] is null
(or unset).
Regards,
Nikita