The example in this article describes the use of reflection mechanism by PHP to find the location of classes and methods. Share it with everyone for your reference, the details are as follows:
//参数1是类名,参数2是方法名 $func = new ReflectionMethod('UnifiedOrder_pub', 'getPrepayId'); //从第几行开始 $start = $func->getStartLine() - 1; //从第几行结束 $end = $func->getEndLine() - 1; //获取路径地址 $filename = $func->getFileName();
The following is a more comprehensive excerpt of the sample code
<?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')); ?>
Readers who are interested in more PHP-related content can check out the special topics on this site: "Summary of PHP ajax skills and applications", "Summary of PHP operations and operator usage", "Summary of PHP network programming skills", "PHP basic syntax" "Introductory Tutorial", "Summary of PHP Office Document Skills (Including Word, Excel, Access, PPT)", "Summary of PHP Date and Time Usage", "Introduction to PHP Object-Oriented Programming", "php String Usage" Summary", "Introduction Tutorial on PHP MySQL Database Operation" and "Summary of Common PHP Database Operation Skills"
I hope this article will be helpful to everyone in PHP programming.