The namespace of class FooBarA
is FooBar
, so the __NAMESPACE__
is working very well. What you are looking for is probably namespaced classname that you could easily get by joining echo __NAMESPACE__ . '\' . __CLASS__;
.
Consider next example:
namespace FooBarFooBar;
use PingPongHongKong;
class A extends HongKongB {
function __construct() {
echo __NAMESPACE__;
}
}
new A;
Will print out FooBarFooBar
which is very correct...
And even if you then do
namespace PingPongHongKong;
use FooBarFooBar;
class B extends FooBarA {
function __construct() {
new A;
}
}
it will echo FooBarFooBar
, which again is very correct...
EDIT: If you need to get the namespace of the nested class within the main that is nesting it, simply use:
namespace PingPongHongKong;
use FooBarFooBar;
class B extends FooBarA {
function __construct() {
$a = new A;
echo $a_ns = substr(get_class($a), 0, strrpos(get_class($a), '\'));
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…