PHP : Does extending class need another #39;use#39; to call namespace?(PHP:扩展类是否需要另一个“使用来调用命名空间?)
问题描述
I'm wondering whether in the situation where I'm extending a class that has already 'use' keyword above it to use specific namespace - do I need to add another 'use' above the inheriting class to use the same namespace? Situation like this:
namespace Core;
use SystemPlugin;
class Front extends Application { }
and now in the Controller, which is called directly without the namespace (using full path):
use SystemPlugin;
class PageController extends Front { }
or would it work without 'use' as well and allow me to use the SystemPlugin namespace:
class PageController extends Front { }
?
No, you need the "use" statement in both files. Use is a file-level keyword and isn't affected by inheritance.
See the scoping rules for importing and the little box describing what I said at the bottom of the manual page.
这篇关于PHP:扩展类是否需要另一个“使用"来调用命名空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHP:扩展类是否需要另一个“使用"来调用命名空间?


- 正确分离 PHP 中的逻辑/样式 2021-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- PHP Count 布尔数组中真值的数量 2021-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- Laravel 仓库 2022-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01