Skip to content

Instantly share code, notes, and snippets.

@ken-muturi
Created November 17, 2013 06:18
Show Gist options
  • Select an option

  • Save ken-muturi/7509998 to your computer and use it in GitHub Desktop.

Select an option

Save ken-muturi/7509998 to your computer and use it in GitHub Desktop.
Get class hierarchy Returns the complete class hierarchy of an object or a class name. Can be used as method or function.
public function getClassHierarchy($obj){
if(is_object($obj)){
$class = get_class($obj);
}
elseif(!class_exists($obj)){
throw new InvalidArgumentException("class $obj is not defined" );
}
$hierarchy = array();
while($class){
$hierarchy[] = $class;
$class = get_parent_class($class);
}
return $hierarchy;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment