Menu

← Back to enum.*

Error Identifier: enum.nameInUse

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

namespace App;

use App\Enums\Status;

enum Status: string
{
	case Active = 'active';
	case Inactive = 'inactive';
}

Why is it reported? #

An enum is being declared with a name that is already in use within the same namespace. This happens when a use statement imports a type with the same short name as the enum being declared. PHP cannot resolve which Status is intended, resulting in a fatal error at runtime.

In the example above, Status is imported via use App\Enums\Status and then an enum named Status is declared in the App namespace, creating a name conflict.

How to fix it #

Rename the enum to avoid the conflict:

 <?php declare(strict_types = 1);
 
 namespace App;

 use App\Enums\Status;

-enum Status: string
+enum UserStatus: string
 {
 	case Active = 'active';
 	case Inactive = 'inactive';
 }

Or use an alias for the imported type:

 <?php declare(strict_types = 1);
 
 namespace App;

-use App\Enums\Status;
+use App\Enums\Status as BaseStatus;

 enum Status: string
 {
 	case Active = 'active';
 	case Inactive = 'inactive';
 }

Or remove the use statement if the imported type is not needed:

 <?php declare(strict_types = 1);
 
 namespace App;

-use App\Enums\Status;
-
 enum Status: string
 {
 	case Active = 'active';
 	case Inactive = 'inactive';
 }

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\Names\UsedNamesRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.