Error Identifier: classConstant.internalEnum
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 (namespace SomeLibrary):
/** @internal */
enum InternalStatus
{
case Active;
case Inactive;
public const DEFAULT = self::Active;
}
// In your code (namespace App):
echo InternalStatus::DEFAULT;
Why is it reported? #
The code accesses a class constant on an enum that is marked with the @internal PHPDoc tag. Internal enums are not part of the public API and are intended to be used only within the package or root namespace where they are defined. Accessing constants on an internal enum from outside its root namespace creates a dependency on an implementation detail that may change or be removed without notice.
How to fix it #
Use a constant from a public (non-internal) enum or class instead:
<?php declare(strict_types = 1);
-echo InternalStatus::DEFAULT;
+echo PublicStatus::DEFAULT;
If no public alternative exists, contact the library maintainer to request a public API for the constant, or define the constant directly in the application code.
How to ignore this error #
You can use the identifier classConstant.internalEnum to ignore this error using a comment:
// @phpstan-ignore classConstant.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: classConstant.internalEnum