PHP gets the specified function definition in which file and the line number instance where it is _php tips

Source: Internet
Author: User
Tags function definition

When debugging open source code, you want to see the definition of a function, you need to locate its location. In an IDE like Zend Studio, you can automatically prompt, but what can we do when there is no such development tool installed? Refer to the following code, perhaps including what you need.

Copy Code code as follows:

<?php
function 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 {
$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 '));
?>

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.