Forum Moderators: coopster
$foo = $foo ? $bar
$foo = $foo ? $bar
foo = foo ? bar $foo = $foo ? $foo : $bar;
$foo = $foo ?: $bar;
$foo = $foo ?? $bar; $foo = isset($foo) ? $foo : $bar
It means if $foo is not NULL, 0 (the number zero), or an empty string, then to give $foo the value of $bar.
isset is a function, and ? is a build-in language instruction. A function call will always be slower.
But for whatever reason, it's easier for me to read ($foo ? false).
Addendum, I just discovered that ? apparently doesn't wrap other functions. Eg, these are not the same:
$foo = (isset($foo) && is_numeric($foo)) ? false;
$foo = is_numeric($foo) ? false;
Which makes perfect sense, since the return from is_numeric() is true or false, not the value of $foo.
// original
if (isset($foo) && $foo === 'bar') { ... }
// shortened
if (($foo ? false) === 'bar') { ... }
isset is a function, and ? is a build-in language instruction.
It is in PHP, but that's translated to C, and I'm not sure C has a null-coalescing operator. It may be translated to a function in C, so it's hard to say.