Error Identifier: classConstant.missingOverride

← Back to classConstant.*

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 HasVersion
{
	public const VERSION = 1;
}

class Foo implements HasVersion
{
	public const VERSION = 2; // ERROR: Constant Foo::VERSION overrides constant HasVersion::VERSION but is missing the #[\Override] attribute.
}

Why is it reported? #

Starting with PHP 8.6, the #[\Override] attribute can be placed on class constants. It declares that the constant is intended to override a constant from a parent class or an implemented interface. If the parent constant is later renamed or removed, PHP reports an error instead of silently turning the overriding constant into an unrelated new one.

This error is reported when a constant overrides another constant but does not have the attribute. Overriding constants declared in traits are not reported.

The check is enabled automatically when checkMissingOverrideMethodAttribute or checkMissingOverridePropertyAttribute is enabled and every analysed PHP version supports #[\Override] on class constants (PHP 8.6+, see phpVersion). It can also be turned on or off explicitly with the checkMissingOverrideConstantAttribute parameter.

How to fix it #

Add the #[\Override] attribute to the overriding constant:

 class Foo implements HasVersion
 {
+	#[\Override]
 	public const VERSION = 2;
 }

When one statement declares several constants (const A = 1, B = 2;), the attribute applies to all of them. Split the declaration so that only the overriding constant carries the attribute:

 class Foo implements HasVersion
 {
-	public const VERSION = 2, OTHER = 3;
+	#[\Override]
+	public const VERSION = 2;
+	public const OTHER = 3;
 }

🔧 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

To also fix the errors you have ignored, use --fix-ignored. Learn more about --fix »

How to ignore this error #

You can use the identifier classConstant.missingOverride to ignore this error using a comment:

// @phpstan-ignore classConstant.missingOverride
codeThatProducesTheError();

You can also use only the identifier key to ignore all errors of the same type in your configuration file in the ignoreErrors parameter:

parameters:
	ignoreErrors:
		-
			identifier: classConstant.missingOverride

Rules that report this error #

  • PHPStan\Rules\Constants\OverridingConstantRule [1]
  • PHPStan\Rules\EnumCases\OverridingEnumCaseRule [1]
Theme
© 2026 PHPStan s.r.o.