Menu

← Back to method.*

Error Identifier: method.internalTrait

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\Service;

use Acme\Library\SomeClass;

// SomeClass uses an @internal trait
$obj = new SomeClass();
$obj->traitMethod();

Why is it reported? #

A method is being called on an object whose declaring class is a trait marked with the @internal tag. The trait is an implementation detail of the library and is not part of its public API. Methods originating from internal traits should not be called from outside the library because the trait may change or be removed in future versions.

How to fix it #

Avoid calling methods that come from internal traits. Look for alternative public API methods that provide the same functionality.

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

 use Acme\Library\SomeClass;

 $obj = new SomeClass();
-$obj->traitMethod();
+$obj->publicApiMethod();

How to ignore this error #

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

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

Rules that report this error #

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

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.