syntax error, unexpected token “;”, expecting “(”¶
Description¶
This syntax error is related to a new PHP feature. In PHP 8.3, a new syntax for dynamic access to class constants was introduced. It was not supported until then.
Example¶
<?php
class A {
public const A = 1;
}
$b = 'A';
echo A::{$b};
?>
Solutions¶
Upgrade PHP to PHP 8.3 or more recent.
Use a call to constant() to reach the value of the class constant.
Static Analysis¶
This error may be tracked down with the following static analysis rules: Classes/DynamicConstantCall.