Answers for "php find all subclasses of class"

PHP
0

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;
	}, []);
}
Posted by: Guest on July-18-2020

Code answers related to "php find all subclasses of class"

Browse Popular Code Answers by Language