How can PHP quickly locate the number of lines or files and locations defined by methods without using the IDE?

高洛峰
Release: 2023-03-05 08:48:02
Original
1032 people have browsed it

php How to quickly locate the number of lines or files and locations defined by methods without using the IDE

With the help of some features of ReflectionMethod, you can quickly get the file and location in which the function or method is defined. For Very helpful for debugging undocumented programs!

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";
}
Copy after login


##Usage:

function_dump('get_affiliate');
Copy after login

Output:

function get_affiliate defined by D:\WWW\admin\affiliate.php(232 - 238)
Copy after login

Thanks for reading, I hope it can help everyone, thank you for your support of this site!

For more articles on how PHP can quickly locate the number of lines or files and locations defined by methods without using the IDE, please pay attention to the PHP Chinese website!


Related labels:
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