Created
November 17, 2013 06:18
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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