foo = getFoo(); const bar = foo || 'default';
alice will equal foo unless it's equal to false, then it'll get the default value.
in PHP it's seems this operator (??) was added in PHP7
The guide for php5 says to write the code like this:
$foo = getFoo(); $bar = $foo ? $foo : 'default';
This is repetitive and looks bad. We have to write $foo twice.
By accident i've stumbled upon the (?:) operator, and this code seems to work:
$foo = getFoo(); $bar = $foo ?: 'default';
This actually seem to work: https://www.tehplayground.com/7ut74LTXkEFsSvLF
but it's not stated in any official guide or place. I am afraid i've either ran into a bug or this won't be supported on different versions of PHP. Does anyone have additional information on this operator?