Menu

← Back to method.*

Error Identifier: method.nonAbstract

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 HelloWorld
{
	public function sayHello(): void;
}

Why is it reported? #

A non-abstract method in a non-abstract class is declared without a body. In PHP, only abstract methods in abstract classes or interfaces can omit the method body. A concrete method in a concrete class must have a body with an implementation, even if the body is empty.

This is a compile-time error in PHP and the code will not run.

How to fix it #

Add a method body:

 class HelloWorld
 {
-	public function sayHello(): void;
+	public function sayHello(): void
+	{
+		// implementation
+	}
 }

If the method is meant to be abstract, declare both the method and the class as abstract:

-class HelloWorld
+abstract class HelloWorld
 {
-	public function sayHello(): void;
+	abstract public function sayHello(): void;
 }

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

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.