Menu

← Back to generics.*

Error Identifier: generics.internalTraitBound

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

// In package vendor/some-library:

/** @internal */
trait InternalTrait
{
}

// In your code:

/**
 * @template T of InternalTrait
 */
class Wrapper
{
}

Why is it reported? #

The @template tag bound references a trait marked as @internal. Internal types are implementation details of their package and should not be referenced from outside that package. Using an internal trait as a generic bound creates a dependency on an API that may change without notice.

How to fix it #

Replace the internal trait with a public type in the template bound:

 /**
- * @template T of InternalTrait
+ * @template T of PublicInterface
  */
 class Wrapper
 {
 }

If no public alternative exists, consider whether the generic bound is necessary, or request that the library expose a public API for the use case.

How to ignore this error #

You can use the identifier generics.internalTraitBound to ignore this error using a comment:

// @phpstan-ignore generics.internalTraitBound
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: generics.internalTraitBound

Rules that report this error #

  • PHPStan\Rules\InternalTag\RestrictedInternalClassNameUsageExtension [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.