PHP uses the reflection mechanism to find the location of classes and methods, and php location _ PHP Tutorial

Source: Internet
Author: User
PHP uses the reflection mechanism to locate the class and method, and php. PHP uses the reflection mechanism to find the location of classes and methods. This article describes the location where php uses the reflection mechanism to find classes and methods. I would like to share with you the location where PHP and php are located by using the reflection mechanism to find classes and methods.

This example describes the location of the search class and method using the reflection mechanism in PHP. We will share this with you for your reference. The details are as follows:

// Parameter 1 is the class name, and parameter 2 is the method name $ func = new ReflectionMethod ('unifiedorder _ pub', 'getprepayid '); // start from the nth row $ start = $ func-> getStartLine ()-1; // end from the nth row $ end = $ func-> getEndLine ()-1; // Obtain the path $ filename = $ func-> getFileName ();

The sample code for excerpt is comprehensive.

<? Phpfunction a () {}class B {public function f () {}} function function_dump ($ funcname) {try {if (is_array ($ funcname )) {$ func = new ReflectionMethod ($ funcname [0], $ funcname [1]); $ funcname = $ funcname [1];} else {// This should be considered as the release of this class when there is only one parameter, probably Baidu $ func = new ReflectionFunction ($ funcname );}} catch (ReflectionException $ e) {echo $ e-> getMessage (); return;} $ start = $ func-> getStartLine ()-1; $ en D = $ func-> getEndLine ()-1; $ filename = $ func-> getFileName (); echo "function $ funcname defined by $ filename ($ start-$ end) \ n ";}function_dump ('A'); function_dump (array ('B', 'F'); $ B = new B (); function_dump (array ($ B, 'F');?>

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.