Menu
Error Identifier: enum.generic
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);
/**
* @template T
*/
enum Status
{
case Active;
case Inactive;
}
Why is it reported? #
PHP enums cannot be generic. Unlike classes and interfaces, enums do not support @template type parameters because enum cases are singleton values and cannot be parameterized with different types.
How to fix it #
Remove the @template tag from the enum. If you need generic behaviour, consider using an interface or a class instead:
<?php declare(strict_types = 1);
-/**
- * @template T
- */
enum Status
{
case Active;
case Inactive;
}
How to ignore this error #
You can use the identifier enum.generic to ignore this error using a comment:
// @phpstan-ignore enum.generic
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: enum.generic
Rules that report this error #
- PHPStan\Rules\Generics\EnumTemplateTypeRule [1]