如何在PHP中实现嵌套名称空间? [英] How to implement nested namespace in PHP?
本文介绍了如何在PHP中实现嵌套名称空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
use level1\level2\level3;
有人可以用一个简单的演示说明吗?
Can someone explain with a simple demo ?
推荐答案
为消除有关不同语法使用的任何混淆,名称空间仅支持两种语法,即放在括号内的或简单组合都可以.我建议如果您使用另一种,请保持一致.
To clear up any confusion regarding different syntax use, namespaces support only two syntaxes, either bracketed or simple-combination both will work. I suggest if you use one over the other, be consistent.
<?php
namespace my\stuff\nested { // <- bracketed syntax
class foo {}
}
?>
它在nested
名称空间内使用括号语法({}
)创建一个类foo
,它等效于
It creates a class foo
inside of the nested
namespace with bracketed syntax ({}
), it is equivalent to
<?php
namespace my\stuff { // bracketed syntax but with a nested look
namespace nested {
class foo {}
}
}
?>
您还可以使用具有简单组合语法(;
)
<?php
namespace mine;
use ultra\long\ns\name; // <- simple-combination syntax
$a = name\CONSTANT;
name\func();
?>
这篇关于如何在PHP中实现嵌套名称空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文