I’m currently considering the use of Reflection classes (ReflectionClass and ReflectionMethod mainly) in my own MVC web framework, because I need to automatically instanciate controller classes and invoke their methods without any required configuration (‘convention over configuration’ approach).
I’m concerned about performance, even though I think that database requests are likely to be bigger bottlenecks than the actual PHP code.
So, I’m wondering if anyone has any good or bad experience with PHP 5 Reflection from a performance point of view.
Besides, I’d be curious to know if any one of the popular PHP frameworks (CI, Cake, Symfony, etc.) actually use Reflection.
Don’t be concerned. Install Xdebug and be sure where the bottleneck is.
There is cost to using reflection, but whether that matters depends on what you’re doing. If you implement controller/request dispatcher using Reflection, then it’s just one use per request. Absolutely negligible.
If you implement your ORM layer using reflection, use it for every object or even every access to a property, and create hundreds or thousands objects, then it might be costly.