PHP命名空间-上一个台阶? [英] PHP Namespaces - go up a level?

查看:83
本文介绍了PHP命名空间-上一个台阶?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

示例1:

命名空间Inori \ Test;

namespace Inori\Test;

MainTest类 { }

class MainTest { }

示例2:

命名空间Inori \ Test \ SubTest;

namespace Inori\Test\SubTest;

SubTest类扩展???? { }

class SubTest extends ???? { }

问题:是否有一种方法可以快速提升命名空间中的级别,以便SubTest可以扩展MainTest? "../MainTest"之类的东西?还是我坚持使用\Inori\Test\MainTest?

Question: is there a way to quickly go up a level in namespace so SubTest could extend MainTest? something like "../MainTest"? Or am I stuck with \Inori\Test\MainTest?

推荐答案

不支持相对名称空间.但是有一个要求: https://bugs.php.net/bug.php?id=52504

Relative namespaces aren't supported. There's a request for it though: https://bugs.php.net/bug.php?id=52504

如果将类导入文件的顶部,那没什么大不了的.

If you import your classes at the top of the file it shouldn't be that big of a deal.

namespace Inori\Test\SubTest;
use Inori\Test\MainTest;

class SubTest extends MainTest { }

这篇关于PHP命名空间-上一个台阶?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆