PHP tip: list all classes available to your script
January 28, 2019
I was fooling around with some raw PHP includes with my content management system and I was wondering how I could get a list of all of the classes that are available.
Luckily, I know how to use Google, so the answer was easy to find.
In case you're wondering, here's all you have to do in order to get a list of all classes available to the script you're currently working on.
Just place this line in the script:
print_r(get_declared_classes());
That's all you really need.
Or, you can format it nicely:
echo '<pre>';
print_r(get_declared_classes());
echo '</pre>';
What you'll get is a printout of an array containing a list of all classes that are available to your PHP script.