rfc:unary_null_coalescing_operator

Differences

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

Link to this comparison view

Next revision
Previous revision
rfc:unary_null_coalescing_operator [2017/06/21 15:21] – created ajfrfc:unary_null_coalescing_operator [2017/09/22 13:28] (current) – external edit 127.0.0.1
Line 3: Line 3:
   * Date: 2017-06-21   * Date: 2017-06-21
   * Author: Andrea Faulds, ajf@ajf.me   * Author: Andrea Faulds, ajf@ajf.me
-  * Status: Under Discussion+  * Status: Declined
   * First Published at: http://wiki.php.net/rfc/unary_null_coalescing_operator   * First Published at: http://wiki.php.net/rfc/unary_null_coalescing_operator
  
Line 20: Line 20:
  
 The unary form of <php>??</php> would provide a faster, non-proscribed alternative to <php>@</php> for retrieving possibly-unset variables. It would also provide a concise, non-redundant way to check the value of a possibly-unset variable. The unary form of <php>??</php> would provide a faster, non-proscribed alternative to <php>@</php> for retrieving possibly-unset variables. It would also provide a concise, non-redundant way to check the value of a possibly-unset variable.
 +
 +One practical use is optional request parameters:
 +
 +<code php>
 +if ($_POST["action"]?? === "submit") {
 +    // Form submission logic
 +} else {
 +    // Form display logic
 +}
 +</code>
 +
 +Another is optional options in, say, a configuration object, or an “options bag” parameter:
 +
 +<code php>
 +if ($optionsBag->safeMode?? === TRUE) {
 +    // Safe mode
 +} else {
 +    // Not safe
 +}
 +</code>
  
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
 None. None.
 +
 +There is an ambiguity in the case where unary <php>??</php> is followed by an operator that can be either unary or binary, i.e. <php>$a?? + $b</php> and <php>$a?? - $b</php>. These continue to be parsed the same (<php>$a ?? (+$b)</php>, <php>$a ?? (-$b)</php>), meaning there is no backwards-compatibility break. 
  
 ===== Proposed PHP Version(s) ===== ===== Proposed PHP Version(s) =====
Line 37: Line 59:
 None. None.
  
-===== Proposed Voting Choices =====+===== Vote =====
 This is a simple language change which should only require a 2/3 majority vote on whether or not to approve it. This is a simple language change which should only require a 2/3 majority vote on whether or not to approve it.
 +
 +Voting started 2017-07-11 and <del>ends 2017-07-18</del> ended 2017-07-18.
 +
 +<doodle title="Accept and merge unary null coalescing operator for PHP 7.2?" auth="ajf" voteType="single" closed="true">
 +   * Yes
 +   * No
 +</doodle>
  
 ===== Patches and Tests ===== ===== Patches and Tests =====
 A php-src patch, including a test, can be found here: https://github.com/php/php-src/pull/2589 A php-src patch, including a test, can be found here: https://github.com/php/php-src/pull/2589
  
-Language specification patch forthcoming.+patch for the language specification, including the same test, can be found here: https://github.com/php/php-langspec/pull/197
  
 ===== Implementation ===== ===== Implementation =====
Line 53: Line 82:
  
 ===== References ===== ===== References =====
-* [[rfc:isset_ternary|PHP RFC: Null Coalesce Operator]]+  * [[rfc:isset_ternary|PHP RFC: Null Coalesce Operator]]
rfc/unary_null_coalescing_operator.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1