Explain the php Reflection applications and php Reflection applications. Php Reflection application, php Reflection application reflection is in the PHP running state, extension analysis PHP program, export or extract detailed information about classes, methods, attributes, parameters, etc. explain the reflection application in php and the php Reflection application.
Reflection is used to expand the analysis of PHP programs in PHP running state, export or extract detailed information about classes, methods, attributes, parameters, and so on, including comments. This kind of dynamic information and the function of dynamically calling an object is called a Reflection API. Reflection is an API used to manipulate the object-oriented model. it is very powerful and can help us build complex and scalable applications.
Its purpose is to automatically load plug-ins, generate documents automatically, and even expand the PHP language.
The php Reflection api consists of several classes that can help us access the metadata of a program or interact with related annotations. With reflection, we can obtain methods implemented by the class, create an instance of the class (different from creating with new), call a method (also different from conventional call), and pass parameters, static methods of the Dynamic Call class.
Reflection APIs are extensions of php built-in oop technology, including some classes, exceptions, and interfaces. they can be used to help us analyze other classes, interfaces, methods, attributes, methods, and extensions. These oop extensions are called reflection.
Through ReflectionClass, we can get the following information about the Person class:
1) constant Contants
2) Property Names
3) Method Names static
4) attribute Static Properties
5) Namespace
6) whether the Person class is final or abstract
Then I went to view the thinkphp source code, and had a different experience for MVC implementation. the exec method in ThinkPHP \ Lib \ Core \ App. class. php
If (! Preg_match ('/^ [A-Za-z] (\ w) * $/', $ action) {// throw new ReflectionException ();} // execute the current operation $ method = new ReflectionMethod ($ module, $ action); # view the method if ($ method-> isPublic ()) {$ class = new ReflectionClass ($ module); # reflection controller // pre-operation if ($ class-> hasMethod ('_ before _'. $ action) {$ before = $ class-> getMethod ('_ before _'. $ action); if ($ before-> isPublic () {$ before-> invoke ($ module );}} // URL parameter binding check if (C ('URL _ PARAMS_BIND ') & $ method-> getNumberOfParameters ()> 0) {switch ($ _ SERVER ['request _ method']) {case 'Post': $ vars =$ _ POST; break; case 'put ': parse_str (file_get_contents ('php: // input'), $ vars); break; default: $ vars =$ _ GET;} $ params = $ method-> getParameters (); foreach ($ params as $ param) {$ name = $ param-> getName (); if (isset ($ vars [$ name]) {$ args [] = $ vars [$ name];} elseif ($ param-> isdefavaluvalueavailable () {$ args [] = $ param-> getDefaultValue ();} else {throw_exception (L ('_ PARAM_ERROR _'). ':'. $ name) ;}$ method-> invokeArgs ($ module, $ args);} else {$ method-> invoke ($ module ); # To execute this operation, we need to call the function} // post-operation if ($ class-> hasMethod ('_ after _'. $ action) {$ after = $ class-> getMethod ('_ after _'. $ action); if ($ after-> isPublic () {$ after-> invoke ($ module );}}
The above is the application of php Reflection. I hope it will help you understand and learn php Reflection.
Articles you may be interested in:
- PHP Reflection mechanism for dynamic proxy code
- Instructions for using reflection technology architecture plug-ins in PHP
- Parse php Reflection applications
- PHP Reflection class ReflectionClass and ReflectionObject usage
- PHP Reflection examples and PHP Reflection APIs
- Example of PHP Reflection class ReflectionClass and ReflectionMethod
- PHP Reflection mechanism usage example
- Example of PHP class reflection usage
Callback reflection extends the analysis of PHP programs in PHP running state, and exports or extracts detailed information about classes, methods, attributes, parameters, and so on ,...