Menu

← Back to return.*

Error Identifier: return.deprecatedEnum

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.

This error is reported by phpstan/phpstan-deprecation-rules.

Code example #

<?php declare(strict_types = 1);

/** @deprecated Use NewStatus instead */
enum OldStatus
{
	case Active;
	case Inactive;
}

function getStatus(): OldStatus
{
	return OldStatus::Active;
}

Why is it reported? #

The native return type declaration of a function or method references an enum that has been marked as deprecated. Using a deprecated enum in a return type means that callers will receive a type that is scheduled for removal, which will require changes in the future.

How to fix it #

Update the return type to use the non-deprecated replacement:

 <?php declare(strict_types = 1);
 
-function getStatus(): OldStatus
+function getStatus(): NewStatus
 {
-	return OldStatus::Active;
+	return NewStatus::Active;
 }

How to ignore this error #

You can use the identifier return.deprecatedEnum to ignore this error using a comment:

// @phpstan-ignore return.deprecatedEnum
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: return.deprecatedEnum

Rules that report this error #

  • PHPStan\Rules\Deprecations\RestrictedDeprecatedClassNameUsageExtension [1] phpstan/phpstan-deprecation-rules

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.