Cannot use dynamic function name in constant expression
Description
This error appears when the name of the function cannot be entirely resolved at compile time. Here, the array cannot be turned into a function or static method name. This also happens for variations on the name, such as using a boolean, an array, or any expression that cannot be resolved at compilation time.
Example
<?php
const Closure1 = ([])(...);
const Closure2 = (-1)(...);
const Closure3 = (true)(...);
var_dump(Closure);
?>
Alternatives
- Use a string for the name of the function or static method.
Related error messages
Changed Behavior
This error may appear following an evolution in behavior, in previous versions. See