Every error reported by PHPStan has an error identifier. Here’s a list of all error identifiers. In PHPStan Pro you can see the error identifier next to each error and filter errors by their identifiers.
Code example #
<?php declare(strict_types = 1);
class Base
{
public const FOO = 1;
}
class Child extends Base
{
#[\Override] // ERROR: Attribute class Override can be used with class constants only on PHP 8.6 and later.
public const FOO = 2;
}
Why is it reported? #
Support for the #[\Override] attribute on class constants was added in PHP 8.6. On older PHP versions, the attribute can only target methods (PHP 8.3+) and properties (PHP 8.5+), and using it on a class constant results in an error.
The PHP version is determined by the phpVersion configuration option, or by the PHP version PHPStan runs with.
How to fix it #
If the code needs to run on PHP versions older than 8.6, remove the attribute:
class Child extends Base
{
- #[\Override]
public const FOO = 2;
}
Alternatively, require PHP 8.6 or later and set phpVersion accordingly.
Non-ignorable error #
This error cannot be ignored using @phpstan-ignore or the ignoreErrors configuration. Non-ignorable errors indicate code that would cause a crash or a fatal error at runtime, or a fundamental problem in the analysed code that must be addressed.
Rules that report this error #
- PHPStan\Rules\Classes\ClassConstantAttributesRule [1]