Error Identifier: enum.caseOverrideAttribute

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

interface HasDefault
{
	public const DEFAULT = 'default';
}

enum Mode implements HasDefault
{
	#[\Override] // ERROR: Attribute class Override can be used with enum cases only on PHP 8.6 and later.
	case DEFAULT;
}

Why is it reported? #

Support for the #[\Override] attribute on class constants and enum cases 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 an enum case 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:

 enum Mode implements HasDefault
 {
-	#[\Override]
 	case DEFAULT;
 }

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\EnumCases\EnumCaseAttributesRule [1]
Theme
© 2026 PHPStan s.r.o.