My intention is to find a short version of:
$x ? $x : $y
where $x gets evaluated only once.
My intention is to find a short version of:
$x ? $x : $y
where $x gets evaluated only once.
From the PHP manual entry on Comparison Operators :
Since PHP 5.3, it is possible to leave out the middle part of the ternary operator. Expression
expr1 ?: expr3
returnsexpr1
ifexpr1
evaluates to TRUE, andexpr3
otherwise.
So, you'll need to be using PHP 5.3 or greater to get this "shortcut" feature. Although, why you'd want a shortcut for an operator that already is a shortcut is another question...