Menu

← Back to new.*

Error Identifier: new.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;

// Assume InternalTrait is marked @internal in vendor/some-package

class MyClass
{
	use \Vendor\InternalTrait; // reported via a different identifier
}

/**
 * @method \Vendor\InternalTrait doSomething()
 */
class Factory
{
	// error: PHPDoc tag @method for doSomething() references
	//        internal trait Vendor\InternalTrait.
}

Why is it reported? #

The code references a trait that is marked as @internal in another package. Internal traits are implementation details of their package and may change or be removed in any release without following semantic versioning. Referencing them from outside the package creates fragile dependencies.

How to fix it #

Avoid referencing internal traits from other packages. Use public API types instead.

 /**
- * @method \Vendor\InternalTrait doSomething()
+ * @method \Vendor\PublicInterface doSomething()
  */
 class Factory
 {
 }

How to ignore this error #

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

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

Rules that report this error #

  • PHPStan\Rules\InternalTag\RestrictedInternalClassNameUsageExtension [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.