Home > Backend Development > PHP Tutorial > PHP gets the file in which the specified function is defined and the line number where it is located_PHP Tutorial

PHP gets the file in which the specified function is defined and the line number where it is located_PHP Tutorial

WBOY
Release: 2016-07-13 10:30:15
Original
999 people have browsed it

When debugging open source code and want to see the definition of a certain function, you need to locate its location. It can be automatically prompted in IDEs like zend studio, but what can we do when such development tools are not installed? Refer to the following code snippet, which may contain what you need.

Copy code The code is as follows:

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];
                                                                                                                                                          > 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'));
? >



http://www.bkjia.com/PHPjc/767086.html

www.bkjia.com

http: //www.bkjia.com/PHPjc/767086.htmlTechArticleWhen debugging open source code and want to see the definition of a certain function, you need to locate its location. It can be automatically prompted in an IDE like zend studio, but when this is not installed...
Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template