Cannot use the %s modifier on a %s¶
Description¶
This is a generic error message for cases where a keyword cannot be used with a class structure. For example, a class constant cannot be abstract or static.
A special case is using final
on a parameter: final is reserved for properties, although properties may be promoted, and also used as a parameter in a constructor. Then, it is not possible to declare the property final, or in the constructor.
final
for class constant was also unavailable in PHP 8.0, and it is now a feature.
Example¶
<?php
class X {
private final const A = 1;
private abstract const B = 1;
private static const C = 1;
function __construct (
final public $p = 1
) {}
}
?>
Literal Examples¶
Cannot use the final modifier on a class constant
Cannot use the abstract modifier on a class constant
Cannot use the static modifier on a class constant
Cannot use the final modifier on a parameter
Solutions¶
Remove the option from the class constant definition.
Upgrade to PHP 8.1 or later, for
final
on class constants.