当我尝试使用导致名称冲突的类时,即.我有两个具有相同名称但名称空间不同的类,我尝试使用它们两个
PHPStorm显示重命名第二个类的提示=给它一个别名as.
<?PHP use MyNamespace\SomeClass; use MyOtherNamespace\SomeClass as SomeOtherClass;
您可以使用PHPStorm重构功能(游标在SomeOtherClass,Shift F6上),它允许重命名别名及其用法.
原文链接:https://www.f2er.com/php/136142.htmlclick here to see the screenshot
如果您已经在脚本中使用了SomeClass而没有别名,那么首先应该设置一个具有相同名称的别名:
use MyNamespace\SomeClass as SomeClass;
然后重构这个别名,如上所述.
另一个解决方案:
If you import a conflicting name,like Foo\MyClass and you already have use Bar\MyClass; in your document,you should be faced with the following prompt
+--------------------------------------------+ | Import class | +--------------------------------------------+ | Alias name: | | [________________________________________] | | | | [X] Always create alias while class import | | | | [ OK ] [ Cancel ] | +--------------------------------------------+
The trick is to check the “Always create alias” checkBox to always be
faced with the prompt while importing.Forgot to mention that you should also uncheck the settings
Settings > Editor > General > Auto Import > [ ] Enable auto-import in
file scopeSettings > Editor > General > Auto Import > [ ] Enable auto-import in
namespace scope