rfc:short_ternary_equal_operator

This is an old revision of the document!


PHP RFC: Null Coalesce Equal 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.

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.1457665102.txt.gz · Last modified: 2017/09/22 13:28 (external edit)