rfc:short_ternary_equal_operator

This is an old revision of the document!


PHP RFC: Short ternary Assignment Operator

Introduction

Most binary expressions in PHP (e.g. `$x = $y op $z;`) have a shorthand form for self assignment (where the lefthand of the binary op is the same as the lefthand of the assignment), in this example: `$x = $x op $y;` is the same as `$x op= $y;`. While it's true for most binary operations, it is not true for the null coalesce operator (the subject of http://wiki.php.net/rfc/null_coalesce_equal_operator ) or the short ternary operator: `?:`.

Proposal

Add an assignment operatory for short ternary expressions such that the following two lines of code are equivalent:

$x = $x ?: $y;
$x ?:= $y;

Thus, the value of right-hand parameter is assigned by value to the left-hand variable if the left-hand variable is currently falsy.

Proposed PHP Version(s)

This proposed for the next PHP 7.x.

Vote

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

Approve Short Ternary Assignment Operator RFC?
Real name Yes No
auroraeosrose (auroraeosrose)  
chx (chx)  
colinodell (colinodell)  
daverandom (daverandom)  
mattwil (mattwil)  
nikic (nikic)  
patrickallaert (patrickallaert)  
pollita (pollita)  
stas (stas)  
svpernova09 (svpernova09)  
weierophinney (weierophinney)  
willfitch (willfitch)  
Final result: 9 3
This poll has been closed.

Vote was closed a few hours after opening (at 9:3 in favor) due to issues with the proposed implementation. It will be reopened at a later time (with a fresh vote).

References

This is essentially the same proposal as https://wiki.php.net/rfc/null_coalesce_equal_operator with a focus on the short ternary operator, rather than the null coalesce operator.

rfc/short_ternary_equal_operator.1458843220.txt.gz · Last modified: 2017/09/22 13:28 (external edit)