Php object-oriented reflection function and Usage Analysis, php object-oriented

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.