Error Identifier: selfOut.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;
// Defined in a third-party package:
// /** @internal */
// trait InternalTrait {}
use ThirdParty\InternalTrait;
class MyClass
{
/**
* @phpstan-self-out self&InternalTrait
*/
public function applyTrait(): void
{
// ...
}
}
Why is it reported? #
The @phpstan-self-out PHPDoc tag references a trait that is marked as @internal. Internal symbols are not meant to be used outside the package or namespace that defines them. Referencing an internal trait in a @phpstan-self-out tag creates a dependency on an internal implementation detail that may change without notice.
How to fix it #
Replace the internal trait with a public interface or class:
<?php declare(strict_types = 1);
namespace App;
-use ThirdParty\InternalTrait;
+use ThirdParty\PublicInterface;
class MyClass
{
/**
- * @phpstan-self-out self&InternalTrait
+ * @phpstan-self-out self&PublicInterface
*/
- public function applyTrait(): void
+ public function applyInterface(): void
{
// ...
}
}
If the trait is internal to the same package, the error will not be reported. The @internal restriction only applies to cross-package usage.
How to ignore this error #
You can use the identifier selfOut.internalTrait to ignore this error using a comment:
// @phpstan-ignore selfOut.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: selfOut.internalTrait
Rules that report this error #
- PHPStan\Rules\InternalTag\RestrictedInternalClassNameUsageExtension [1]