Get all defined classes of a parent class in php

Taking Wrikken’s answer and correcting it using Scott BonAmi’s suggestion and you get:

$children = array();
foreach( get_declared_classes() as $class ){
  if( is_subclass_of( $class, 'foo' ) )
    $children[] = $class;
}

The other suggestions of is_a() and instanceof don’t work for this because both of them expect an instance of an object, not a classname.

Leave a Comment