Take the State of PHP 2026 Survey →

Null Coalesce Equal Operator View as Markdown

Implemented (PHP 7.4)
Authors
Midori Kocak, mtkocak@gmail.com
Date
2016-03-09
Version
0.1.0
Source
wiki.php.net/rfc/null_coalesce_equal_operator

Vote

Approve Equal Null Coalesce Operator RFC and merge patch into master? closed
Yes
37
No
4
41 voters
aharvey Yes 2016-03-25 03:55
ajf No 2016-03-25 13:40
brianlmoon Yes 2016-03-24 16:04
colinodell Yes 2016-03-24 15:20
daverandom Yes 2016-03-24 15:15
davey Yes 2016-03-24 19:56
dmitry Yes 2016-03-25 07:18
dragoonis Yes 2016-03-25 12:28
francois Yes 2016-03-25 12:55
frozenfire Yes 2016-03-24 18:17
galvao Yes 2016-03-27 19:50
guilhermeblanco Yes 2016-03-28 02:56
jwage Yes 2016-03-24 15:13
klaussilveira Yes 2016-03-28 11:23
krakjoe No 2016-03-31 08:51
laruence No 2016-03-28 03:54
lcobucci Yes 2016-03-26 21:29
leigh Yes 2016-03-25 12:17
levim No 2016-03-25 15:51
lstrojny Yes 2016-03-30 12:42
malukenho Yes 2016-03-09 18:19
marcio Yes 2016-03-24 20:36
mariano Yes 2016-03-24 18:24
mbeccati Yes 2016-03-24 15:39
mcmic Yes 2016-03-29 05:48
mrook Yes 2016-04-01 07:09
ocramius Yes 2016-03-24 15:49
patrickallaert Yes 2016-03-24 16:21
pauloelr Yes 2016-03-30 17:44
pierrick Yes 2016-03-25 05:44
pollita Yes 2016-03-24 15:09
ralphschindler Yes 2016-03-28 04:41
stas Yes 2016-03-24 16:43
svpernova09 Yes 2016-03-24 15:14
toby Yes 2016-03-24 15:20
tpunt Yes 2016-03-24 16:03
trowski Yes 2016-03-24 15:40
weierophinney Yes 2016-03-24 15:47
yohgaki Yes 2016-03-25 10:37
zeev Yes 2016-03-29 20:06
zimt Yes 2016-03-25 17:25

Discussions on the mailing list

[RFC Proposal] Null Coalesce Equal Operator
by Midori Kocak · 21 messages
[RFC][Voting] Null Coalesce Equal Operator
by Midori Kocak · 4 messages
null coalesce addition assignment operator ??+=
by Andreas Hennings · 12 messages
Coalesce assign operator (??=) implemented
by Nikita Popov · 3 messages
Supports to ?:= assignment operator
by David Rodrigues · 2 messages
??= and function calls
by Ilija Tovilo · 5 messages

RFC text

Copied from wiki.php.net, last synchronized Oct 13, 2026 11:51 UTC

Introduction

Combined assignment operators have been around since 1970's, appearing first in the C Programming Language. For example, $x = $x + 3 can be shortened to $x += 3. With PHP being a web focused language, the ?? operator is often used to check something's existence like $username = $_GET['user'] ?? 'nobody'; However, because variable names are often much longer than $username, the use of ?? for self assignment creates repeated code, like $this->request->data['comments']['user_id'] = $this->request->data['comments']['user_id'] ?? ‘value’;. It is also intuitive to use combined assignment operator null coalesce checking for self assignment.

Proposal

Despite ?? coalescing operator being a comparison operator, coalesce equal or ??=operator is an assignment operator. If the left parameter is null, assigns the value of the right paramater to the left one. If the value is not null, nothing is made.

// The folloving lines are doing the same
$this->request->data['comments']['user_id'] = $this->request->data['comments']['user_id'] ?? 'value';
// Instead of repeating variables with long names, the equal coalesce operator is used
$this->request->data['comments']['user_id'] ??= 'value';

The value of right-hand parameter is copied if the left-hand parameter is null.

Proposed PHP Version(s)

This proposed for the next PHP 7.x.

Patches and Tests

A pull request with a working implementation, targeting master, is here: https://github.com/php/php-src/pull/1795

Vote

As this is a language change, a 2/3 majority is required. A straight Yes/No vote is being held.

Voting started at 2016/03/24 16:08 and will be closed at 2016/04/02.

Vote: Approve Equal Null Coalesce Operator RFC and merge patch into master? — Yes: 37 · No: 4 (closed)

References

Links to external references, discussions or RFCs

http://programmers.stackexchange.com/questions/134118/why-are-shortcuts-like-x-y-considered-good-practice

Rejected Features

Keep this updated with features that were discussed on the mail lists.