As of PHP 5.3, the ternary operator can be shortened to just ?:, as documented at http://us2.php.net/ternary#language.operators.comparison.ternary:

Since PHP 5.3, it is possible to leave out the middle part of the ternary operator. Expression expr1 ?: expr3 returns expr1 if expr1 evaluates to TRUE, and expr3 otherwise.

However, the code sniffer returns two errors when this operator is used:

ERROR: An operator statement must be followed by a single space
ERROR: There must be a single space before an operator statement

Comments

klausi’s picture

Status: Active » Closed (won't fix)

I would still say that there should be a space between "?" and ":", which works fine, too.