Error Identifier: trait.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
namespace App;
use SomeLibrary\Helper;
trait Helper
{
}
Why is it reported? #
A trait is being declared with a name that is already in use within the same namespace, typically because a use import statement has already introduced the same name. PHP does not allow two symbols with the same name in the same namespace scope, and this will cause a fatal error at runtime.
How to fix it #
Rename the trait to avoid the name conflict:
<?php
namespace App;
use SomeLibrary\Helper;
-trait Helper
+trait AppHelper
{
}
Or alias the imported name to avoid the collision:
<?php
namespace App;
-use SomeLibrary\Helper;
+use SomeLibrary\Helper as LibraryHelper;
trait Helper
{
}
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]