Menu

← Back to enum.*

Error Identifier: enum.caseWithValue

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);

enum Color
{
    case Red = 1;
    case Green = 2;
    case Blue = 3;
}

Why is it reported? #

The enum is a pure (non-backed) enum, meaning it has no scalar type declaration (like : int or : string). Pure enums cannot have values assigned to their cases. Only backed enums (declared with : int or : string) can have values. This is a PHP language constraint.

How to fix it #

If the cases need values, declare the enum as a backed enum:

 <?php declare(strict_types = 1);
 
-enum Color
+enum Color: int
 {
     case Red = 1;
     case Green = 2;
     case Blue = 3;
 }

If the enum does not need values, remove them from the cases:

 <?php declare(strict_types = 1);
 
 enum Color
 {
-    case Red = 1;
-    case Green = 2;
-    case Blue = 3;
+    case Red;
+    case Green;
+    case Blue;
 }

Non-ignorable error #

This error cannot be ignored using @phpstan-ignore or the ignoreErrors configuration. Non-ignorable errors indicate code that would cause a crash or a fatal error at runtime, or a fundamental problem in the analysed code that must be addressed.

Rules that report this error #

  • PHPStan\Rules\Classes\EnumSanityRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.