# Equal Null coalescing operator ??= https://github.com/php/php-src/pull/1795

- Thread: https://externals.io/message/91549
- Original archive: https://news-web.php.net/php.internals/91549
- Started by Midori Kocak on 2016-03-08T17:59:37+00:00
- Messages: 4
- 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

---

## #91549 — Midori Kocak — 2016-03-08T17:59:37+00:00

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

Remember my question? 

$this->request->data['comments']['user_id'] = $this->request->data['comments']['user_id'] ?? ‘value’;

I want to check if some var is null and if the same var is null set the same var to ‘value’.

Hence I am repeating the same variable after the equal operator, this does not feels right.

So I feel that we need another operator like “??=“ similar to +=;

$this->request->data['comments']['user_id’]  ??= ‘value’. So if the var is null it’s set to ‘value’ and else stays the same.

I implemented it. Please check this here: https://github.com/php/php-src/pull/1795 <https://github.com/php/php-src/pull/1795>

Midori

---

## #91551 — Ralph Schindler — 2016-03-08T18:55:35+00:00

URL: https://externals.io/message/91549#91551 · In reply to: #91549

> Remember my question?
>
> $this->request->data['comments']['user_id'] = $this->request->data['comments']['user_id'] ?? ‘value’;
>
> I want to check if some var is null and if the same var is null set the same var to ‘value’.
>
> Hence I am repeating the same variable after the equal operator, this does not feels right.
>
> So I feel that we need another operator like “??=“ similar to +=;
>
> $this->request->data['comments']['user_id’]  ??= ‘value’. So if the var is null it’s set to ‘value’ and else stays the same.
>
> I implemented it. Please check this here: https://github.com/php/php-src/pull/1795 <https://github.com/php/php-src/pull/1795>

+1
I like this idea and would like to see it as an RFC.

-ralph

---

## #91552 — Fleshgrinder — 2016-03-08T20:17:55+00:00

URL: https://externals.io/message/91549#91552 · In reply to: #91549

> Remember my question? 
> 
> $this->request->data['comments']['user_id'] = $this->request->data['comments']['user_id'] ?? ‘value’;
> 
> I want to check if some var is null and if the same var is null set the same var to ‘value’.
> 
> Hence I am repeating the same variable after the equal operator, this does not feels right.
> 
> So I feel that we need another operator like “??=“ similar to +=;
> 
> $this->request->data['comments']['user_id’]  ??= ‘value’. So if the var is null it’s set to ‘value’ and else stays the same.
> 
> I implemented it. Please check this here: https://github.com/php/php-src/pull/1795 <https://github.com/php/php-src/pull/1795>
> 
> Midori
> 

+1

Very handy addition!

-- 
Richard "Fleshgrinder" Fussenegger

---

## #91554 — Sara Golemon — 2016-03-08T21:41:51+00:00

URL: https://externals.io/message/91549#91554 · In reply to: #91549

>
> $this->request->data['comments']['user_id'] = $this->request->data['comments']['user_id'] ?? ‘value’;
> $this->request->data['comments']['user_id’]  ??= ‘value’;
>
RFC it so there's a proper vote process, but you've got mine (pending
a proper look at the PR).  Honestly feels like it was an oversight
when the coalesce operator was added.

-Sara
