This article mainly introduces the object-oriented reflection function and usage of PHP, and analyzes the concept and concrete usage of PHP5 object-oriented reflection with the example form, and the friends can refer to the following
This paper describes the object-oriented reflection function and usage of PHP. Share to everyone for your reference, as follows:
An individual's understanding of the definition of reflection:
First, you have to say what is reflection. For a novice, the concept of reflection often gives a sense of indefinitely and does not know how to proceed.
reflection refers to the following: refers to the PHP running state, the extension of the analysis of the PHP program, export or extract information about classes, methods, properties, parameters and other details, but also include comments. This dynamic acquisition of information and the ability to dynamically invoke an object's methods is called the Reflection API. Reflection is an API that manipulates the meta-model of an object-oriented paradigm and is powerful in helping us to build complex, scalable applications . (Note:This kind of reverse operation in PHP is completely PHP5. )
Here I use an example to illustrate:
Class test{ private $A; Public $B; protected $C; Public Function test () { return ' This is a test function '; }} Instantiate a reflection Class Reflectionclass$obj=new Reflectionclass (' test '); Echo $obj. " <br> ";//instantiate the test class and access its test method $obj2= $obj->newinstance (); Echo $obj 2->test ();
Personal instances Return results:
/** * xxx.php * ============================================== * Copy Right 2012-2015 *-------------------------------- --------------* This is not a free software, without any authorization are not allowed to use and spread. * ============================================== * @Author: yexianming * @Email: LangWaiShiGe@hotmail.com * @Version: Zend studio10.6.2 php5.4.38 apache2.2 * * class [class Test] {@@ d:\www\myprojecttest\index5.php 13-21-constants [0] { }-static properties [0] {}-static methods [0] {}-Properties [3] {Property [private $A] Property [public $B] property [protected $C]}-Methods [1] {method [public Method test] {@@ d:\www\myprojecttest\index5.php 18-20}} }this is a test function
The above is the whole content of this article, I hope that everyone's study has helped.