syntax error, unexpected ‘throw’ (T_THROW)¶
Description¶
throw
is not an expression until PHP 8.0. Until then, it cannot be used as part of another expression, such as the left part of or
, an argument, or inside parenthesis.
After PHP 8.0, one could use it as part of an expression.
Example¶
<?php
$x ?? throw new \Exception('Missing value for x');
?>
Solutions¶
Upgrade to PHP 8.0 or more recent.
Convert the
or
to anifthen
structure.
Changed Behavior¶
This error may appear following an evolution in behavior, in previous versions. See throwIsAnExpression.
Changed Behavior¶
This error may appear following an evolution in behavior, in previous versions. See throwIsAnExpression.