HI there,
I was wondering if there is a way in php 5.3+ to get a list of defined namespaces within an application. so
if
file 1 has namespace F
Firstly, to see if a class exists, used class_exists.
Secondly, you can get a list of classes with namespace using get_declared_classes.
In the simplest case, you can use this to find a matching namespace from all declared class names:
function namespaceExists($namespace) {
$namespace .= "\\";
foreach(get_declared_classes() as $name)
if(strpos($name, $namespace) === 0) return true;
return false;
}
Another example, the following script produces a hierarchical array structure of declared namespaces:
Gives:
Array
(
[FirstNamespace] =>
[SecondNamespace] => Array
(
[FirstSubNamespace] =>
)
[ThirdNamespace] => Array
(
[FirstSubNamespace] =>
[SecondSubNamespace] =>
)
)