Menu

← Back to staticMethod.*

Error Identifier: staticMethod.private

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
{
	private static function computeSecret(): int
	{
		return 42;
	}
}

class Bar
{
	public function doFoo(): int
	{
		return Foo::computeSecret();
	}
}

Why is it reported? #

The code calls a private static method from a class that is not the declaring class. Private methods are only accessible from within the class that defines them. They are not accessible from subclasses or any other class. This results in a fatal error at runtime.

How to fix it #

If the method needs to be called from outside the class, change its visibility to public or protected:

 <?php declare(strict_types = 1);
 
 class Foo
 {
-	private static function computeSecret(): int
+	public static function computeSecret(): int
 	{
 		return 42;
 	}
 }

Alternatively, expose the functionality through a public method:

 <?php declare(strict_types = 1);
 
 class Foo
 {
 	private static function computeSecret(): int
 	{
 		return 42;
 	}
+
+	public static function getResult(): int
+	{
+		return self::computeSecret();
+	}
 }

 class Bar
 {
 	public function doFoo(): int
 	{
-		return Foo::computeSecret();
+		return Foo::getResult();
 	}
 }

How to ignore this error #

You can use the identifier staticMethod.private to ignore this error using a comment:

// @phpstan-ignore staticMethod.private
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: staticMethod.private

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.