If you need to get the classes defined in a specific file, you could use a RegExp or other simple parsing. You might even have luck comparing the results of a get_declared_classes() prior and after including the file. The most elegant solutions is the one I found over at stackoverflow.com:
$tokens = token_get_all( file_get_contents('c2.php') ); $class_token = false; foreach ($tokens as $token) { if ( !is_array($token) ) continue; if ($token[0] == T_CLASS) { $class_token = true; } else if ($class_token && $token[0] == T_STRING) { echo "Found class: $token[1]\n"; $class_token = false; } }
This one uses the internal PHP parser to tokenize the file. So any valid PHP syntax is recognized and will return the correct class names.