Menu

← Back to method.*

Error Identifier: method.internalClass

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);

namespace App;

use Vendor\Internal\Service;

function doFoo(Service $service): void
{
	$service->process(); // ERROR: Call to method process() of internal class Vendor\Internal\Service from outside its root namespace Vendor.
}

Why is it reported? #

The method is being called on an object whose class is marked as @internal. Internal classes are not part of the public API and are intended to be used only within the package or namespace where they are defined. Calling methods on an internal class from outside its root namespace violates this contract. The class may change or be removed without notice in future versions of the package.

How to fix it #

Use the public API provided by the package instead of accessing internal classes directly:

 <?php declare(strict_types = 1);
 
 namespace App;

-use Vendor\Internal\Service;
+use Vendor\PublicService;

-function doFoo(Service $service): void
+function doFoo(PublicService $service): void
 {
 	$service->process();
 }

If no public alternative exists, consider reaching out to the package maintainers to request a public API for the functionality needed.

How to ignore this error #

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

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

Rules that report this error #

  • PHPStan\Rules\InternalTag\RestrictedInternalMethodUsageExtension [1] [2]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.