Get a List of System Declared Classes and User Defined Class Names in an Array With the PHP Function Get_Declared_Classes
Get a list of system declared classes and user defined class names in an array with php function get_declared_classes.
Using the introspection functions in php you can inspect the characteristics of an object at runtime. This includes its name, parent class (if any), properties and methods. Introspection is a powerful technique that allows you to write generic debuggers, serializers etc.
In PHP, the introspection functions include class_exists(), get_class() and get_class_methods(). These are designed to help you understand your code at a lower level. They are all available in PHP 5.0 and later, and are similar to the C++ feature of runtime type information.
The get_declared_classes() function returns an array containing all the system declared classes (for example, PDO and XML reader) as well as any class you have defined yourself or from 3rd party libraries you may have included in your script. The order of the class in the return array is not guaranteed to be the same as they were declared, but it should be in the same order that they are included in the code that is executed at runtime.
In previous versions of PHP, the get_declared_classes() return value included the name of the parent class before the child class. This is no longer the case in PHP 7.0 and later. To make it easier to find a class in the returned list, you can use the function sort() to sort the list alphabetically. You can also pass a string to get_declared_classes() that will be used as the prefix for all class names that are listed in the returned array.