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);
interface WithFinal
{
final public const F = 1;
}
enum OverridesFinal implements WithFinal
{
case F; // ERROR: Enum case OverridesFinal::F overrides final constant WithFinal::F.
}
Why is it reported? #
An enum case is a class constant of the enum. When the enum implements an interface that declares a constant with the same name, the case overrides that constant. Constants declared final (PHP 8.1+) cannot be overridden, so PHP throws a fatal error when the enum is declared.
How to fix it #
Rename the enum case so it no longer collides with the final constant:
enum OverridesFinal implements WithFinal
{
- case F;
+ case Foo;
}
If the constant is meant to be overridden, remove the final modifier from the interface constant:
interface WithFinal
{
- final public const F = 1;
+ public const F = 1;
}
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\EnumCases\OverridingEnumCaseRule [1]