Skip to content

Instantly share code, notes, and snippets.



Created Apr 2, 2019
What would you like to do?
Get all the classes and functions in a file
use Roave\BetterReflection\BetterReflection;
use Roave\BetterReflection\Reflector\ClassReflector;
use Roave\BetterReflection\Reflector\FunctionReflector;
use Roave\BetterReflection\SourceLocator\Type\SingleFileSourceLocator;
$fileName = 'my-file-with-stuff.php';
$sourceLocator = new SingleFileSourceLocator($fileName, (new BetterReflection())->astLocator());
$classReflector = new ClassReflector($sourceLocator);
$allTheClasses = $classReflector->getAllClasses();
$allTheFunctions = (new FunctionReflector($sourceLocator, $classReflector))->getAllFunctions();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment