While tools such as phpDocumentor provide quite detailed information about an entire series of classes, it can be useful to get a quick dump that lists all the functions and methods defined in a list of files.
The program in Example 7-42 loops through a list of files, includes them, and then uses the Reflection classes to gather information about them. Once the master list is compiled, the functions and methods are sorted alphabetically and printed out.
This code uses both the Reflection classes and also a couple of PHP functions, get_declared_classes( ) and get_declared_functions( ), that aren't part of the Reflection classes, but help with introspection.
It's important to filter out any built-in PHP classes and functions; otherwise, the report will be less about your code and more about your PHP installation. This is handled in two different ways. Since get_declared_classes( ) doesn't distinguish between user and internal classes, the code calls ReflectionClass::isUserDefined( ) to check. The get_defined_function( ) call, on the other hand, actually computes this for you, putting the information in the user array element.
Since it's easier to scan the output of a sorted list, the script sorts the arrays of methods and functions. Since multiple classes can have the same method, you need to use a user-defined sorting method, sort_methods( ), which first compares two methods by their class names and then by their method names.
Once the data is sorted, it's a relatively easy task to loop though the merged arrays, gather up the filename and starting line numbers, and print out a report.
Here's the results of running the PEAR HTTP class through the script:
HTTP::Date() | /usr/lib/php/HTTP.php | 38 HTTP::head() | /usr/lib/php/HTTP.php | 144 HTTP::negotiateLanguage() | /usr/lib/php/HTTP.php | 77 HTTP::redirect() | /usr/lib/php/HTTP.php | 186