Menu

← Back to method.*

Error Identifier: method.staticCall

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

Foo::doFoo();

Why is it reported? #

An instance method is being called statically using the :: operator. The method doFoo() is not declared as static, so it requires an object instance to be called on. Calling it statically is deprecated in modern PHP versions and can lead to errors if the method uses $this.

How to fix it #

Call the method on an instance of the class:

-Foo::doFoo();
+$foo = new Foo();
+$foo->doFoo();

If the method does not use $this and is intended to be called statically, declare it as static:

 class Foo
 {
-	public function doFoo(): void
+	public static function doFoo(): void
 	{
 	}
 }

How to ignore this error #

You can use the identifier method.staticCall to ignore this error using a comment:

// @phpstan-ignore method.staticCall
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: method.staticCall

Rules that report this error #

  • PHPStan\Rules\Methods\CallStaticMethodsRule [1]
  • PHPStan\Rules\Methods\StaticMethodCallableRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.