PHP advanced programming (2) _ PHP Tutorial

Source: Internet
Author: User
Tags reflector
PHP advanced programming (2 ). PHP5 has a complete reflection API and adds the reverse engineering capability for classes, interfaces, functions, methods, and extensions. In addition, the reflection API provides methods to retrieve functions, classes, and methods. PHP 5 has a complete reflection API and adds the reverse engineering capability for classes, interfaces, functions, methods, and extensions. In addition, the reflection API provides methods to retrieve document comments in functions, classes, and methods. You can use the Reflection API to analyze other classes, interfaces, methods, attributes, functions, and extensions. The following example shows the definition of PHP Reflection:

Reflection::export(new ReflectionClass('Reflection'));

The output is as follows:

Class [ 
 
   class Reflection ] {  - Constants [0] {  }  - Static properties [0] {  }  - Static methods [2] {    Method [ 
  
    static public method getModifierNames ] {      - Parameters [1] {        Parameter #0 [ 
   
     $modifiers ]      }    }    Method [ 
    
      static public method export ] {      - Parameters [2] {        Parameter #0 [ 
     
       Reflector $reflector ]        Parameter #1 [ 
      
        $return ] } } } - Properties [0] { } - Methods [0] { }}
      
     
    
   
  
 

From the printed results, we can see that export is a public static method of the Reflection class. It provides two parameters, one must provide the reflector type, and the other is optional, bool type. There are more than export reflection APIs. through these APIs, we can also query the metadata of classes, dynamically call static methods of classes, and reflection can also be used to create an automatic and stable writing system. Reflection APIs define a large number of is and has functions that can be used to execute condition judgments in code. For example, isUserDefined () is used to determine which classes are user-defined.

(To be continued)

Http://www.bkjia.com/PHPjc/812981.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/812981.htmlTechArticlePHP 5 has a complete reflection API, added the ability to reverse engineer on classes, interfaces, functions, methods and extensions. In addition, the reflection API provides methods to retrieve functions, classes, and methods...

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.