php find all subclasses of class code example
Example: php find all subclasses of class
/* Loops through all loaded classes (get_declared_classes()) and
returns an array of subclasses of the provided $parent */
function getSubclasses(string $parent):array {
return array_reduce(get_declared_classes(), function($subclasses, $class) use ($parent) {
if (is_subclass_of($class, $parent)) {
$subclasses[] = $class;
}
return $subclasses;
}, []);
}