Menu

← Back to traitUse.*

Error Identifier: traitUse.internalInterface

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;

// Defined in a third-party package:
// namespace ThirdParty;
// /** @internal */
// interface InternalInterface {}

use ThirdParty\InternalInterface;

class Foo
{
    use InternalInterface;
}

Why is it reported? #

The use statement inside a class body references an interface that is marked as @internal. Internal interfaces are not part of the public API of the package that defines them. They may change or be removed in any version without notice.

While using an interface in a use statement is already incorrect (only traits can be used this way), the internal access error is also reported because the referenced symbol is internal to another package.

How to fix it #

Only traits can be used in a class body use statement. If you need functionality from the library, look for a public trait that provides it:

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

-use ThirdParty\InternalInterface;
+use ThirdParty\PublicTrait;

 class Foo
 {
-    use InternalInterface;
+    use PublicTrait;
 }

If the interface should be implemented rather than used as a trait, use implements instead:

-class Foo
+class Foo implements SomePublicInterface
 {
-    use InternalInterface;
 }

If the interface is internal to your own project, the error will not be reported when referencing it from within the same root namespace.

How to ignore this error #

You can use the identifier traitUse.internalInterface to ignore this error using a comment:

// @phpstan-ignore traitUse.internalInterface
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: traitUse.internalInterface

Rules that report this error #

  • PHPStan\Rules\InternalTag\RestrictedInternalClassNameUsageExtension [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.