7 Feb 2008

php5 beauty, reflection api

the php4 way

beside very usefull features like try/catch php5 has many little nifty features. i had to fetch all methods of a class, regardless of visibility. get_class_methods(mixed $class_name) has been introduced in php4 and is only able to get public methods. I needed a way to list protected/private methods of a class (without the need of executing them).

Reflection API
The reflection api (intreduced in php5) is a much more flexible way to find out information about a class, object, methods, properties, etc.

PHP5 Reflection API Documentation

List all methods of a class (public, private, protected, final, static):

<?php
$r = new ReflectionClass('Exception');
print_r($r->getMethods());
?>