Reflection is definitely here to stay. You may use it, but keep in mind it is said to be slow and overkill for simple UseCases. Using one of the functions in the Classes/Objects function package is often the faster alternative.
A UseCase where Reflection comes in handy is when parsing for annotations in the DocBlock of a class. For instance, PHPUnit uses the annotations @test to tell the PHPUnit TestRunner that it should consider a method a test. The @covers annotation will help it collect Code Coverage data. The FLOW3 framework makes use of Annotations for their AOP framework.
Unfortunately, some of the newer additions to PHP > 5.3, are not documented yet that much. Just look at the SPL. Same thing. That doesn't mean you cannot use it though. The Reflection API is very expressive and easy to figure out from the method names. And Google often has blog posts about how to use certain extensions. For the Reflection API, check out:
- http://www.phpriot.com/articles/reflection-api
- http://mark-story.com/posts/view/using-the-php-reflection-api-for-fun-and-profit
- http://www.tuxradar.com/practicalphp/16/4/0
- http://weierophinney.net/matthew/archives/125-PHP-5s-Reflection-API.html
and for SPL
- http://www.phpro.org/tutorials/Introduction-to-SPL.html
Something cool I just discovered recently. As of 5.1.2, you can invoke the Reflection API from the command line too:
$php --rf strtotime
Function [ <internal:date> function strtotime ] {
- Parameters [2] {
Parameter #0 [ <required> $time ]
Parameter #1 [ <optional> $now ]
}
}