Error Identifier: enum.debugInfoNotSupported

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

enum Suit
{
	case Hearts;
	case Spades;

	public function __debugInfo(): array
	{
		return ['name' => $this->name];
	}
}

Why is it reported? #

Before PHP 8.6, enums cannot declare the __debugInfo() magic method. Loading such an enum on an older PHP version is a fatal error: Enum Suit cannot include magic method __debugInfo. PHP 8.6 lifted this restriction, so the method is allowed only when the analysed code targets PHP 8.6 or later.

How to fix it #

If the project requires PHP 8.6 or later, configure PHPStan to analyse the code for it by setting the phpVersion option.

If older PHP versions must be supported, remove the method and expose the debug information through a regular method instead:

 enum Suit
 {
 	case Hearts;
 	case Spades;

-	public function __debugInfo(): array
+	public function toDebugArray(): array
 	{
 		return ['name' => $this->name];
 	}
 }

Or declare the enum with __debugInfo() only when running on PHP 8.6 or later:

<?php declare(strict_types = 1);

if (PHP_VERSION_ID >= 80600) {
	enum Suit
	{
		case Hearts;
		case Spades;

		public function __debugInfo(): array
		{
			return ['name' => $this->name];
		}
	}
}

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]
Theme
© 2026 PHPStan s.r.o.