get_class() will give me the eventual class of an object.
I want to know all the chain of parent classes. How can this be done?
You can use
class_parents — Return all parent classes of the given class in an arrayExample:
print_r(class_parents('RecursiveDirectoryIterator'));
will output
Array
(
    [FilesystemIterator] => FilesystemIterator
    [DirectoryIterator] => DirectoryIterator
    [SplFileInfo] => SplFileInfo
)
                        You could call get_parent_class repeatedly until it returns false:
function getClassHierarchy($object) {
    if (!is_object($object)) return false;
    $hierarchy = array();
    $class = get_class($object);
    do {
        $hierarchy[] = $class;
    } while (($class = get_parent_class($class)) !== false);
    return $hierarchy;
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With