Menu

← Back to use.*

Error Identifier: use.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 SomeOtherNamespace\Foo;

class Foo
{
}

Why is it reported? #

A use import introduces a name that is already taken by another declaration in the same namespace scope. In the example, the use statement imports SomeOtherNamespace\Foo as Foo, but there is also a class named Foo declared in the same namespace. This creates a naming conflict that PHP cannot resolve.

This is a PHP compile-time error – having two definitions for the same name in the same scope is not allowed.

How to fix it #

Use an alias for the imported name to avoid the conflict:

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

-use SomeOtherNamespace\Foo;
+use SomeOtherNamespace\Foo as OtherFoo;

 class Foo
 {
 }

Or remove the conflicting use statement if it is not needed:

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

-use SomeOtherNamespace\Foo;
-
 class Foo
 {
 }

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.