(PHP 8 >= 8.4.0)
ReflectionConstant::getNamespaceName — Gets namespace name
Gets the namespace name of the constant.
This function has no parameters.
The namespace name, or an empty string for the global namespace.
Example #1 ReflectionConstant::getNamespaceName() example
<?php
namespace Foo {
const BAR = 'bar';
var_dump((new \ReflectionConstant('Foo\BAR'))->getNamespaceName());
}
namespace {
const BAR = 'bar';
var_dump((new \ReflectionConstant('BAR'))->getNamespaceName());
}
?>
The above example will output:
string(3) "Foo" string(0) ""