Now we have nullcoalesca operator in PHP:
$a = $a ?? $b;
And nullcoalesce assignment operator:
$a ??= $b;
(which is equivalent of previous example with nullcoalesce operator).
Also we have a short syntax for ternary operator:
$a = $a ?: $b;
which is equivalent to:
$a = $a ? $b : $a;
Maybe we can make a syntax for assignment with short ternary operator?
Somethink like that:
$a ?:= $b;
which would be an equivalent of:
$a = $a ?: $b;
I now, this looks ugly, but maybe we can find another tokens for this
assignments?
Now we have nullcoalesca operator in PHP:
$a = $a ?? $b;
And nullcoalesce assignment operator:
$a ??= $b;
(which is equivalent of previous example with nullcoalesce operator).
Also we have a short syntax for ternary operator:
$a = $a ?: $b;
which is equivalent to:
$a = $a ? $b : $a;
Maybe we can make a syntax for assignment with short ternary operator?
Somethink like that:$a ?:= $b;
which would be an equivalent of:
$a = $a ?: $b;
I now, this looks ugly, but maybe we can find another tokens for this
assignments?
Hi,
I think it is a very bad idea. Unlike null coalescing (??), short ternary
(?:) operates on all truthy and falsy values, that is, it implicitly
coerces values into boolean before deciding which side to return. This
makes it error prone and has led to countless bugs in userland code.
There is a reason static analysis warns against usage of such constructs.
Kind regards,
Faizan