how to obtain all subclasses of a class in php

liysd picture liysd · Aug 12, 2010 · Viewed 8.2k times · Source

Is it possible to get all subclasses of given class in php?

Answer

Artefacto picture Artefacto · Aug 12, 2010
function getSubclassesOf($parent) {
    $result = array();
    foreach (get_declared_classes() as $class) {
        if (is_subclass_of($class, $parent))
            $result[] = $class;
    }
    return $result;
}

Coincidentally, this implementation is exactly the one given in the question linked to by Vadim.