Menu

← Back to classConstant.*

Error Identifier: classConstant.final

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
{
	final public const VERSION = '1.0';
}

class Child extends Base
{
	public const VERSION = '2.0';
}

Why is it reported? #

A class constant is overriding a constant that has been declared as final in a parent class or interface. Final constants cannot be overridden by child classes. This is a PHP language constraint enforced at runtime.

In the example above, Child::VERSION attempts to override Base::VERSION, which is declared as final.

This error is also reported when a class declares a final constant that overrides a non-final constant from a used trait. Trait constants must keep the same finality when redeclared.

How to fix it #

Remove the overriding constant declaration from the child class:

 <?php declare(strict_types = 1);
 
 class Child extends Base
 {
-	public const VERSION = '2.0';
 }

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\Traits\ConflictingTraitConstantsRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.