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 */
enum InternalStatus {
case Active;
public static string $label = 'Status';
}
}
namespace App {
function test(): string {
return \Vendor\InternalStatus::$label; // error: Access to static property $label of internal enum Vendor\InternalStatus from outside its root namespace Vendor.
}
}
Why is it reported? #
A static property is being accessed on an enum that is marked as @internal. Internal enums are not part of the public API of the package that defines them and may change or be removed without notice. Accessing static properties on internal enums creates a fragile dependency on implementation details.
How to fix it #
Use the public API of the package instead of accessing static properties on internal enums:
namespace App {
function test(): string {
- return \Vendor\InternalStatus::$label;
+ return \Vendor\PublicStatus::$label;
}
}
If the enum is internal to your own project and the usage is within the same root namespace, the error will not be reported.
How to ignore this error #
You can use the identifier staticProperty.internalEnum to ignore this error using a comment:
// @phpstan-ignore staticProperty.internalEnum
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: staticProperty.internalEnum