PHP 5 Reflection API performance

前端 未结 10 981
不知归路
不知归路 2020-12-02 20:11

I\'m currently considering the use of Reflection classes (ReflectionClass and ReflectionMethod mainly) in my own MVC web framework, because I need to automatically instancia

相关标签:
10条回答
  • 2020-12-02 20:22

    CodeIgniter defenitly uses Reflections. And i bet the others also do. Look into Controller class in the system/controller folder in ci installation.

    0 讨论(0)
  • 2020-12-02 20:23

    Sometimes using something like call_user_func_array() can get you what you need. Don't know how the performance differs.

    0 讨论(0)
  • 2020-12-02 20:24

    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.

    0 讨论(0)
  • 2020-12-02 20:30

    Besides, I'd be curious to know if any one of the popular PHP frameworks (CI, Cake, Symfony, etc.) actually use Reflection.

    http://framework.zend.com/manual/en/zend.server.reflection.html

    "Typically, this functionality will only be used by developers of server classes for the framework."

    0 讨论(0)
提交回复
热议问题