Error Identifier: method.override

← Back to method.*

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 Foo
{
	#[\Override]
	public function doSomething(): void
	{
	}
}

Why is it reported? #

A method has the #[\Override] attribute, but it does not actually override any method from a parent class or implemented interface. The #[\Override] attribute (introduced in PHP 8.3) is meant to signal that a method is intentionally overriding a parent method. If no parent method exists, the attribute is incorrect and the error is reported to help catch typos in method names or incorrect class hierarchies.

The same check applies to property hooks (PHP 8.4+). A get or set hook with the #[\Override] attribute has to override a hook of the same kind from a parent class or an interface. A property with storage inherited from the parent class counts as having a get hook, and also a set hook unless it is readonly:

<?php declare(strict_types = 1);

class Foo
{
	public int $prop {
		#[\Override]
		get => 1;
	}
}

How to fix it #

Remove the #[\Override] attribute if the method is not intended to override a parent method, or fix the class hierarchy so that the parent method exists.

 <?php declare(strict_types = 1);
 
 class Foo
 {
-	#[\Override]
 	public function doSomething(): void
 	{
 	}
 }

Or ensure the class extends the correct parent:

 <?php declare(strict_types = 1);
 
-class Foo
+class Foo extends Bar
 {
 	#[\Override]
 	public function doSomething(): void
 	{
 	}
 }

🔧 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\Methods\OverridingMethodRule [1]
  • PHPStan\Rules\Properties\OverridingPropertyRule [1]
Theme
© 2026 PHPStan s.r.o.