Created
August 8, 2014 15:07
-
-
Save bustbr/0dd42598805ee6ee3f97 to your computer and use it in GitHub Desktop.
PHP Reflection: List Derived Classes
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
| /** | |
| * Return a list of all class names derived from this class. | |
| * | |
| * This function is not caching the result on purpose: derived classes would | |
| * share the same static variable and classes defined after this function | |
| * was once called wouldn't show up. | |
| * Implement a caching mechanism yourself if you think you need it. | |
| * @return array | |
| */ | |
| private static function _derivedClasses() { | |
| $derivedClasses = []; | |
| foreach (get_declared_classes() as $className) { | |
| if (is_subclass_of($className, static::class)) { | |
| $derivedClasses[] = $className; | |
| } | |
| } | |
| return $derivedClasses; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment