Error Identifier: enum.caseOverride

← Back to enum.*

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

enum Suit
{
	#[\Override]
	case Hearts; // ERROR: Enum case Suit::Hearts has #[\Override] attribute but does not override any constant.
	case Spades;
}

Why is it reported? #

The #[\Override] attribute on an enum case (PHP 8.6+) declares that the case overrides a constant declared in an interface implemented by the enum. If no implemented interface declares a constant with the same name, the attribute is incorrect and PHP throws a fatal error.

This typically happens when the interface constant was renamed or removed, when the enum no longer implements the interface, or when the case name contains a typo.

How to fix it #

If the case is not meant to override an interface constant, remove the attribute:

 enum Suit
 {
-	#[\Override]
 	case Hearts;
 	case Spades;
 }

If the case is supposed to override an interface constant, make sure the enum implements the interface and the names match:

-enum Suit
+enum Suit implements HasDefault
 {
 	#[\Override]
-	case Hearts;
+	case DEFAULT;
 	case Spades;
 }

🔧 This error is auto-fixable. PHPStan can fix it for you. Run the analysis with the --fix option to rewrite the affected code:

vendor/bin/phpstan analyse --fix

Learn more about --fix »

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\Constants\OverridingConstantRule [1]
  • PHPStan\Rules\EnumCases\OverridingEnumCaseRule [1]
Theme
© 2026 PHPStan s.r.o.