PHP has the function get_declared_classes() which allows you to get a list of all the available system and user defined classes in an array. This post looks at how to use the get_declared_classes() function, the output from it and how to sort the list into alphabetical order.
Using get_declared_classes()
get_declared_classes() returns a zero based array containing all the classes available to your script, including both system declared classes (such as PDO and XMLReader) and the classes you have declared yourself or from any 3rd party libraries you have included in your script.
The following example illustrates this (the examples below assume we have two user defined classed called foo and bar):
and an extract of the result:
Sorting the result into alphabetical order
If you want to sort the list of classes into alphabetical order, you could do this instead:
and an extract of the result:
Conclusion
The get_declaed_functions() function is a great way of getting a complete list of classes that are available on your install of PHP and from your own and 3rd party PHP libraries.
0 comments:
Post a Comment