Menu

Error Identifier: enum.caseOutsideOfEnum

← Back to enum.*

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

class Foo
{
	case Active;
}

Why is it reported? #

The case keyword for declaring enum members is only valid inside enum declarations. Using it inside a regular class, interface, or trait is a syntax-level mistake. PHP enums were introduced in PHP 8.1, and the case keyword has special meaning only within an enum body.

This usually happens when the enum keyword was accidentally replaced with class, or the declaration was meant to be an enum but was written as a class or interface.

How to fix it #

Change the declaration to an enum:

-class Foo
+enum Foo
 {
 	case Active;
 }

If you need a backed enum with string or integer values:

-class Foo
+enum Foo: string
 {
-	case Active;
+	case Active = 'active';
 }

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\EnumCases\EnumCaseOutsideEnumRule [1]
Theme
A
© 2026 PHPStan s.r.o.