PHP uses a reflection mechanism to find where classes and methods are located, PHP is located _php tutorial

Source: Internet
Author: User
Tags php database

PHP uses a reflection mechanism to find where classes and methods are located, where PHP is located


The example in this article describes how PHP uses the reflection mechanism to find the location of classes and methods. Share to everyone for your reference, as follows:

Parameter 1 is the class name, parameter 2 is the method name $func = new Reflectionmethod (' unifiedorder_pub ', ' Getprepayid ');//starting from the first line $start = $func Getstartline ()-1;//end from the first few lines $end = $func->getendline ()-1;//get path address $filename = $func->getfilename ();

The following is a complete sample code excerpt

<?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 when there is only one parameter as the release of this class, presumably, self-baidu      $func = new Reflectionfunction ($funcname);    }  } catch ( Reflectionexception $e) {    echo $e->getmessage ();    return;  }  $start = $func->getstartline ()-1;  $end = $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 '));? >

Read more about PHP related content readers can view the topic: "Php+ajax Tips and Applications Summary", "PHP operation and operator Usage Summary", "PHP Network Programming Skills Summary", "PHP Basic Grammar Primer Tutorial", "PHP operation Office Document Tips Summary ( including word,excel,access,ppt), PHP date and Time usage summary, PHP Primer for object-oriented programming, PHP string usage Summary, PHP+MYSQL database Operations Starter Tutorial, and A summary of common PHP database operation techniques

I hope this article is helpful to you in PHP programming.

http://www.bkjia.com/PHPjc/1122884.html www.bkjia.com true http://www.bkjia.com/PHPjc/1122884.html techarticle PHP uses a reflection mechanism to find where classes and methods are located, where PHP is located This example describes how PHP uses the reflection mechanism to find where classes and methods are located. Share for the big ...

  • 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.