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
![Reflection API for PHP Reflection API for PHP](https://img.php.cn/upload/article/000/000/013/deeec3781ec8ced3fd87c35fec1cd163-0.png)
##Person class contains one member variable and three members Method
Get the method and property list of the $student object
![Reflection API for PHP Reflection API for PHP](https://img.php.cn/upload/article/000/000/013/deeec3781ec8ced3fd87c35fec1cd163-1.png)
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
![Reflection API for PHP Reflection API for PHP](https://img.php.cn/upload/article/000/000/013/c07b4aca3dcc80e0d7760e04f1f38949-2.png)
Through the class() function Get class information
Print results:
![Reflection API for PHP Reflection API for PHP](https://img.php.cn/upload/article/000/000/013/c07b4aca3dcc80e0d7760e04f1f38949-3.png)
Through this reflection API, you can use hooks to implement plug-in functions, dynamic proxies, etc.
Dynamic proxy examples found on the Internet
![Reflection API for PHP Reflection API for PHP](https://img.php.cn/upload/article/000/000/013/63514d4364679e22b92860493717e689-4.png)
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