As of PHP 5.3, the middle part of the ternary ?:
operator can be omitted.
foo ?: bar
is equivalent to foo ? foo : bar
. So true ?: ...
always returns the first true
.
foo ? : bar
with the meaning of "nothing if true" is and was always invalid, since this expression has to return something, it can't just return nothing. If anything, you'd want this: foo ? null : bar
.