加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 13:03:29 所属栏目:PHP教程 来源:网络整理
导读:当我尝试使用导致名称冲突的类时,即.我有两个具有相同名称但名称空间不同的类,我尝试使用它们两个 PHPStorm显示重命名第二个类的提示=给它一个别名as. ?phpuse MyNamespaceSomeClass;use MyOtherNamespaceSomeClass as SomeOtherClass; 我希望能够在指针位
当我尝试使用导致名称冲突的类时,即.我有两个具有相同名称但名称空间不同的类,我尝试使用它们两个 PHPStorm显示重命名第二个类的提示=给它一个别名as.
<?php
use MyNamespaceSomeClass;
use MyOtherNamespaceSomeClass as SomeOtherClass;

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

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

click here to see the screenshot

如果您已经在脚本中使用了SomeClass而没有别名,那么首先应该设置一个具有相同名称的别名:

use MyNamespaceSomeClass as SomeClass;

然后重构这个别名,如上所述.

另一个解决方案:

If you import a conflicting name,like FooMyClass and you already have use BarMyClass; 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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读