PHP名称空间可以包含变量吗? [英] Can PHP namespaces contain variables?
本文介绍了PHP名称空间可以包含变量吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
PHP名称空间可以包含变量吗?如果是这样,该如何完成?
Can PHP namespaces contain variables? If so, how can this be accomplished?
推荐答案
否.您可以在声明名称空间后设置变量,但是变量将始终存在于全局范围内.它们永远不会绑定到名称空间.您可以从
No. You can set a variable after declaring a namespace, but variables will always exist in the global scope. They are never bound to namespaces. You can deduce that from the absence of any name resolution descriptions in
- 常见问题解答:您需要了解的有关名称空间的内容( PHP 5> = 5.3.0)
- FAQ: things you need to know about namespaces (PHP 5 >= 5.3.0)
也将不允许使用语法在命名空间中定位变量.
There would also be no allowed syntax to locate variables in a namespace.
print \namespace\$var; // syntax error
print "${namespace\\var}"; // "unexpected T_NS_SEPARATOR"
这篇关于PHP名称空间可以包含变量吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文