rfc:null_coalesce_equal_operator

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
rfc:null_coalesce_equal_operator [2016/03/09 22:58]
midorikocak version
rfc:null_coalesce_equal_operator [2019/01/22 10:36] (current)
nikic Implemented
Line 1: Line 1:
-====== PHP RFC: Null Coalesce Equal Operator ======+====== PHP RFC: Null Coalescing Assignment ​Operator ======
   * Version: 0.1.0   * Version: 0.1.0
   * Date: 2016-03-09   * Date: 2016-03-09
   * Author: Midori Kocak, mtkocak@gmail.com   * Author: Midori Kocak, mtkocak@gmail.com
-  * Status: ​Under Discussion+  * Status: ​Implemented (in PHP 7.4)
   * First Published at: http://​wiki.php.net/​rfc/​null_coalesce_equal_operator   * First Published at: http://​wiki.php.net/​rfc/​null_coalesce_equal_operator
  
Line 9: Line 9:
 ===== Introduction ===== ===== Introduction =====
  
-Combined assignment operators ​are around since 1970'​s,​ appearing first in the C languageConsider the following code ''<​nowiki>​$x = $x + 3</​nowiki>'' ​that has the ability to be shortened ​into ''<​nowiki>​$x += 3</​nowiki>''​. ​Hence PHP is a web focused language, ''??''​ operator is used to check something'​s existence like ''<​nowiki>​$username = $_GET['​user'​] ?? '​nobody';</​nowiki>''​ However ​due to common ​variable names are much longer than ''​$username'' ​the use of ''​??'' ​self assignmentcreates repeated code''<​nowiki>​$this->​request->​data['​comments'​]['​user_id'​] = $this->​request->​data['​comments'​]['​user_id'​] ?? ‘value’;</​nowiki>''​ It is also intuitive to use combined assignment operator null coalesce checking for self assignment. ​+Combined assignment operators ​have been around since 1970'​s,​ appearing first in the C Programming LanguageFor example, ​''<​nowiki>​$x = $x + 3</​nowiki>'' ​ ​can ​be shortened ​to ''<​nowiki>​$x += 3</​nowiki>''​. ​With PHP being a web focused language, ​the ''??''​ operator is often used to check something'​s existence like ''<​nowiki>​$username = $_GET['​user'​] ?? '​nobody';</​nowiki>'' ​ However, because ​variable names are often much longer than $usernamethe use of ?? for self assignment creates repeated code, like ''<​nowiki>​$this->​request->​data['​comments'​]['​user_id'​] = $this->​request->​data['​comments'​]['​user_id'​] ?? ‘value’;</​nowiki>''​It is also intuitive to use combined assignment operator null coalesce checking for self assignment. ​
  
 ===== Proposal ===== ===== Proposal =====
  
-Despite ''??'' ​coalesce ​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.+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.
  
 <code php> <code php>
Line 35: Line 35:
  
 As this is a language change, a 2/3 majority is required. A straight Yes/No vote is being held. 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.
 +
 +<doodle title="​Approve Equal Null Coalesce Operator RFC and merge patch into master?"​ auth="​midorkocak"​ voteType="​single"​ closed="​true">​
 +   * Yes
 +   * No
 +</​doodle>​
  
 ===== References ===== ===== References =====
rfc/null_coalesce_equal_operator.1457564292.txt.gz · Last modified: 2017/09/22 13:28 (external edit)