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 Vendor {
/** @internal */
trait InternalTrait {
public function doSomething(): void {}
}
}
namespace App {
class Foo {
/** @var \Vendor\InternalTrait */
public $helper; // error: Property $helper references internal trait Vendor\InternalTrait in its type.
}
}
Why is it reported? #
A property type references a trait that has been marked as @internal. Internal traits are implementation details of their package and are not meant to be used by external code. They may change or be removed without notice in future versions. Referencing an internal trait in a property type declaration creates a fragile dependency on implementation details.
How to fix it #
Replace the internal trait reference with the package’s public API:
namespace App {
class Foo {
- /** @var \Vendor\InternalTrait */
- public $helper;
+ public \Vendor\PublicInterface $helper;
}
}
If no public alternative exists, contact the library maintainers to request a public API for the functionality.
How to ignore this error #
You can use the identifier property.internalTrait to ignore this error using a comment:
// @phpstan-ignore property.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: property.internalTrait