Php object-oriented reflection function and Usage Analysis, php object-oriented
This article describes the php object-oriented reflection function and usage. We will share this with you for your reference. The details are as follows:
My personal understanding of reflection definition:
First, let's talk about reflection. For a newbie, the concept of reflection often gives people a feeling of ignorance and does not know how to proceed.
Reflection refers:In the PHP running state, it refers to the Extension Analysis of the PHP program, exporting or extracting detailed information about classes, methods, attributes, parameters, and so on, and also 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. (Note:Php is only available after PHP5.)
The following is an example:
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 $ obj2-> test ();
Results returned by a personal instance:
/** * xxx.php * ============================================== * Copy right 2012-2015 * ---------------------------------------------- * This is not a free software, without any authorization is 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