Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

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;
	}, []);
}
 
PREVIOUS NEXT
Tagged: #php #find #subclasses #class
ADD COMMENT
Topic
Name
5+6 =