Pete Boere wrote (on 18/09/2014):
I'm seeing '??' as analogous to the way JS developers use '||', and I use
that all the time when writing JS.
Actually, JS's || is more analogous to the existing ?: operator, because
it checks for truthiness, not definedness (!empty() rather than isset(),
in PHP terms).
PHP:
echo false ?: "" ?: 0 ?: "default";
JS:
console.log( false || "" || 0 || "default" );
The behaviour around undefined variables is a bit different, but that's
a property of JS as a language, not any suppression by the || operator
(console.log(x) with undefined x is an error; console.log(x.y) with x as
an empty object is not).
--
Rowan Collins
[IMSoP]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php