Home >Backend Development >PHP Tutorial >Detailed graphic explanation of php's reflection API

Detailed graphic explanation of php's reflection API

伊谢尔伦
伊谢尔伦Original
2017-07-01 10:41:541120browse

PHP5 adds a new feature: Reflection. This feature enables PHP to reverse-engineer class, interface, function, method and extension. Through the PHP code, you can get all the information of a object and interact with it.

PHP's reflection API, that is, when PHP is running, by analyzing the PHP program, the class, method, 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

Member methods

Get the method and attribute list of the $student object


##The ReflectionClass class reports information about a class

The output result is: name say set get

You can also use the class function to obtain the information associated with the object attributes

array


Get class information through the class() function

Print results:


Through this reflection API, you can do Hook implements plug-in functions, dynamic proxy, etc.

Examples of dynamic agents found online

The above is the detailed content of Detailed graphic explanation of php's reflection API. For more information, please follow other related articles on 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