PHP5 adds a new feature: Reflection. This feature enables PHP to reverse-engineer class, interface, function, method and extension. Through PHP code, you can get all the information of an object and interact with it.
PHP’s reflection API means that by analyzing the PHP program while PHP is running, the classes, methods, attributes, parameters and other information to which the object belongs can be derived.
How to use reflection API
Sample code Person.php
##Person class contains one member variable and three members Method
Get the method and property list of the $student object
The ReflectionClass class reports information about a class
Output The result is: name say __set __get
You can also use the class function to obtain the information of the associative array of object attributes
Through the class() function Get class information
Print results:
Through this reflection API, you can use hooks to implement plug-in functions, dynamic proxies, etc.
Dynamic proxy examples found on the Internet
For more articles related to PHP’s reflection API, please pay attention to the PHP Chinese website!
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn