# Coalesce assign operator (??=) implemented

- Thread: https://externals.io/message/103774
- Original archive: https://news-web.php.net/php.internals/103774
- Started by Nikita Popov on 2019-01-22T10:33:35+00:00
- Messages: 3
- RFC: Null Coalesce Equal Operator (Implemented (PHP 7.4)) — https://externals.io/rfc/null_coalesce_equal_operator.md
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #103774 — Nikita Popov — 2019-01-22T10:33:35+00:00

URL: https://externals.io/message/103774#103774

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

---

## #103776 — bjorn.x.larsson@telia.com — 2019-01-22T15:51:58+00:00

URL: https://externals.io/message/103774#103776 · In reply to: #103774

Hi,

Excellent work! I have been waiting for this :)

Sara, I came to think on the Short ternary Assignment Operator RFC.
Would this implementation make that one more feasible, given it
passes a vote?

r//Björn Larsson

Den 2019-01-22 kl. 11:33, skrev Nikita Popov:

> 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

---

## #103777 — Nikita Popov — 2019-01-22T16:39:44+00:00

URL: https://externals.io/message/103774#103777 · In reply to: #103776

On Tue, Jan 22, 2019 at 4:51 PM Björn Larsson <bjorn.x.larsson@telia.com>
wrote:

> Hi,
>
> Excellent work! I have been waiting for this :)
>
> Sara, I came to think on the Short ternary Assignment Operator RFC.
> Would this implementation make that one more feasible, given it
> passes a vote?
>

From an implementation perspective ?:= is nearly identical to ??=, so
implementing it should be quite simple now. Whether an RFC for it would
pass is a different question, I'm not a big fan personally...

Nikita


> r//Björn Larsson
>
> Den 2019-01-22 kl. 11:33, skrev Nikita Popov:
>
> > […]
> https://github.com/php/php-src/commit/a50198d0fef652ca052cda642d6e98a9101eb73f
> > […]
