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

Link to this comparison view

Next revision
Previous revision
rfc:null_coalesce_equal_operator [2016/03/09 17:03]
midorikocak created
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.9 +  * Version: 0.1.0 
-  * Date: 2016-03-09 ​(use today'​s date here)+  * Date: 2016-03-09
   * Author: Midori Kocak, mtkocak@gmail.com   * Author: Midori Kocak, mtkocak@gmail.com
-  * Status: ​Draft (or Under Discussion or Accepted or Declined)+  * 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
 ===== Introduction ===== ===== Introduction =====
-This is a suggested template for PHP Request for Comments (RFCs). Change this template to suit your RFC.  ​Not all RFCs need to be tightly specified. ​ Not all RFCs need all the sections below. +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 languagethe ''??''​ operator is often used to check something's existence like ''<​nowiki>​$username = $_GET['​user'​?? '​nobody';</​nowiki>'' ​ Howeverbecause variable names are often much longer than $username, the use of ?? for self assignment creates repeated codelike ''<​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
-Read https://wiki.php.net/​rfc/​howto carefully! +
- +
- +
-Quoting [[http://​news.php.net/​php.internals/​71525|Rasmus]]:​ +
- +
-PHP is and should remain: +
-> 1) pragmatic ​web-focused language +
-> 2) a loosely typed language +
-> 3) a language which caters to the skill-levels and platforms of a wide range of users +
- +
-Your RFC should move PHP forward following his vision. As [[http://​news.php.net/​php.internals/​66065|said by Zeev Suraski]] "​Consider only features which have significant traction ​to +
-large chunk of our userbase, and not something ​that could be useful in some +
-extremely specialized edge cases [...Make sure you think about the full contextthe huge audience out there, the consequences ​of  ​making the learning curve steeper with +
-every new featureand the scope of the goodness that those new features bring."​ +
- +
-===== Introduction ===== +
-The elevator pitch for the RFCThe first paragraph in this section will be slightly larger ​to give it emphasis; please write a good introduction.+
 ===== Proposal ===== ===== Proposal =====
-All the features and examples of the proposal. 
-To [[http://​news.php.net/​php.internals/​66051|paraphrase Zeev Suraski]]explain hows the proposal brings substantial ​value to be considered +Despite ''??''​ coalescing operator being a comparison operator, coalesce equal or ''??​=''​operator is an assignment operatorIf the left parameter is nullassigns ​the value of the right paramater ​to the left one. If the value is not null, nothing is made.
-for inclusion in one of the world'​s most popular programming languages.+
-Remember that the RFC contents should be easily reusable in the PHP Documentation.+<code php> 
 +// 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';​ 
-===== Backward Incompatible Changes ===== +The value of right-hand parameter ​is copied if the left-hand parameter is null. 
-What breaks, and what is the justification for it?+
 ===== Proposed PHP Version(s) ===== ===== Proposed PHP Version(s) =====
-List the proposed PHP versions that the feature will be included in.  Use relative versions such as "next PHP 7.x" or "next PHP 7.x.y"​. 
-===== RFC Impact ===== +This proposed for the next PHP 7.x.
-==== To SAPIs ==== +
-Describe ​the impact to CLI, Development web server, embedded ​PHP etc.+
-==== To Existing Extensions ​==== +===== Patches and Tests =====
-Will existing extensions be affected?+
-==== To Opcache ==== +A pull request ​with a working implementation,​ targeting master, is here: https://​github.com/​php/​php-src/​pull/​1795
-It is necessary to develop RFC'​s ​with opcache in mindsince opcache ​is a core extension distributed with PHP.+
-Please explain how you have verified your RFC's compatibility with opcache.+===== Vote =====
-==== New Constants ==== +As this is a language change, a 2/3 majority is required. A straight Yes/No vote is being held.
-Describe any new constants so they can be accurately and comprehensively explained in the PHP documentation.+
-==== php.ini Defaults ==== +Voting started at 2016/03/24 16:08 and will be closed at 2016/04/02.
-If there are any php.ini settings then list: +
-  * hardcoded default values +
-  * php.ini-development values +
-  * php.ini-production values+
-===== Open Issues ===== +<doodle title="​Approve Equal Null Coalesce Operator ​RFC and merge patch into master?"​ auth="​midorkocak"​ voteType="​single"​ closed="​true">​ 
-Make sure there are no open issues when the vote starts! +   * Yes 
- +   * No 
-===== Unaffected PHP Functionality ===== +</doodle>
-List existing areas/​features of PHP that will not be changed by the RFC. +
- +
-This helps avoid any ambiguity, shows that you have thought deeply about the RFC's impact, ​and helps reduces mail list noise. +
- +
-===== Future Scope ===== +
-This sections details areas where the feature might be improved in future, but that are not currently proposed in this RFC. +
- +
-===== Proposed Voting Choices ===== +
-Include these so readers know where you are heading and can discuss the proposed voting options. +
- +
-State whether this project requires a 2/3 or 50%+1 majority (see [[voting]]) +
- +
-===== Patches and Tests ===== +
-Links to any external patches and tests go here. +
- +
-If there is no patch, make it clear who will create a patch, or whether a volunteer to help with implementation is needed. +
- +
-Make it clear if the patch is intended to be the final patch, or is just a prototype. +
- +
-===== Implementation ===== +
-After the project is implemented,​ this section should contain  +
-  - the version(s) it was merged to +
-  - a link to the git commit(s) +
-  - a link to the PHP manual entry for the feature+
 ===== References ===== ===== References =====
 Links to external references, discussions or RFCs Links to external references, discussions or RFCs
 ===== Rejected Features ===== ===== Rejected Features =====
 Keep this updated with features that were discussed on the mail lists. Keep this updated with features that were discussed on the mail lists.
rfc/null_coalesce_equal_operator.1457542991.txt.gz · Last modified: 2017/09/22 13:28 (external edit)