Skip to content

Instantly share code, notes, and snippets.

@bustbr
Created August 8, 2014 15:07
Show Gist options
  • Select an option

  • Save bustbr/0dd42598805ee6ee3f97 to your computer and use it in GitHub Desktop.

Select an option

Save bustbr/0dd42598805ee6ee3f97 to your computer and use it in GitHub Desktop.
PHP Reflection: List Derived Classes
/**
* 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