How to check if a class belongs to a certain namespace
You can use get_class()
to obtain the class of the object, then you can use strops()
on it to find out if it contains the namespace. There isn't an equivalent get_namespace()
function.
Example:
function is_in_namespace($namespace, $object) {
return strpos(get_class($object), $namespace . '\\') === 0;
}
function get_namespace($object) {
$class = get_class($object);
$pos = strrpos($class, '\\');
return substr($class, 0, $pos);
}