website/errors/use.nameInUse.md
<?php declare(strict_types = 1);
namespace App;
class Foo
{
}
use SomeOtherNamespace\Foo;
A use import introduces a name that is already taken by another declaration in the same namespace scope. In the example, the class Foo is declared in the App namespace, and then a use statement tries to import SomeOtherNamespace\Foo as Foo. 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.
Use an alias for the imported name to avoid the conflict:
<?php declare(strict_types = 1);
namespace App;
class Foo
{
}
-use SomeOtherNamespace\Foo;
+use SomeOtherNamespace\Foo as OtherFoo;
Or remove the conflicting use statement if it is not needed:
<?php declare(strict_types = 1);
namespace App;
class Foo
{
}
-
-use SomeOtherNamespace\Foo;