【发布时间】:2014-04-10 07:29:29
【问题描述】:
我试图弄清楚命名空间在 PHP 中是如何工作的,但很难理解何时需要全局命名空间前缀。举个例子:
index.php
namespace MySpace;
require_once 'file.php';
Test::hello();
hi();
文件.php
class Test {
public static function hello () {
echo 'hello';
}
}
function hi() {
echo 'hi';
}
这行不通,但写 \Test::hello() 会并回显“hello”和“hi”。
为什么 hi() 也不需要 \?
【问题讨论】:
标签: php namespaces