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.

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;
}

?>

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

Solutions

  • Remove the option from the class constant definition.

  • Upgrade to PHP 8.1 or later, for final on class constants.