Object-oriented reflection function and usage of PHP

Source: Internet
Author: User
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.


Related Article

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.