PHP在另一个没有反斜杠的命名空间中使用根命名空间


PHP use root namespace within another namespace without backslash

我的根命名空间中有一堆类。我想在另一个命名空间中使用它们,但我不知道如何"包括"它们,这样我就不必在开头添加反斜杠。

class A {
    public static $a = 1;
}
namespace B {
    use '; // apparently invalid 
    class C {
        static function D { return A::$a; } // desired syntax
    }
}
'B'C::D(); // expected result is 1

这可能吗?

无论命名空间是否为"根",都无法使用use导入整个命名空间。你能做的最好的事情是:

use A;

use语句更改为

use 'A-

然后你会得到你想要的语法-