PHPStorm重构快捷方式在use语句中给出别名

前端之家收集整理的这篇文章主要介绍了PHPStorm重构快捷方式在use语句中给出别名前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
当我尝试使用导致名称冲突的类时,即.我有两个具有相同名称名称空间不同的类,我尝试使用它们两个 PHPStorm显示重命名第二个类的提示=给它一个别名as.
<?PHP
use MyNamespace\SomeClass;
use MyOtherNamespace\SomeClass as SomeOtherClass;

我希望能够在指针位于类上时随时调用提示符,最好是从键盘快捷键.这可能吗?

您可以使用PHPStorm重构功能(游标在SomeOtherClass,Shift F6上),它允许重命名别名及其用法.

click 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 scope

Settings > Editor > General > Auto Import > [ ] Enable auto-import in
namespace scope

https://laracasts.com/discuss/channels/general-discussion/phpstorm-importing-namespaces-with-aliases/replies/99388

原文链接:https://www.f2er.com/php/136142.html

猜你在找的PHP相关文章