syntax error, unexpected token “?”¶
Description¶
? is used in several syntaxes in PHP.
as
nullin a type specification (argument, returntype, property, class constant), when it is the first type specified:?A $aas the terny operator
$condition ? $then : $else. Then, the condition must be a complete expression.
Example¶
<?php
// an unfinished ternary operation
$a = 1 + ? 3 : 2 ;
// ? should be written null in a type specification
function foo(a|? $a) {}
?>
Solutions¶
Finish the expression before the
?in a ternary operation.Use the
nulltype when specifying a type.