在PHP中获取被调用函数列表 [英] Get a called functions list in PHP
问题描述
在PHP中,get_included_files()
返回一个包含所包含文件名称的数组.
In PHP, get_included_files()
returns an array with the names of included files.
以类似的方式,有没有办法获得带有带有参数的被调用函数的名称的数组?
In a similar fashion, is there any way to get an array with the names of called functions with parameters?
推荐答案
我试图实现您想要的目标,并最终提出了一个合理的解决方案.
I was trying to achieve what you want and finally came up with an reasonable solution.
创建一个名为Debug
的类,并将其包含在要调试的每个文件的上方.为自己构建一个函数,该函数可以很好地打印存储在$calls
中的信息.
Make a class named Debug
and include that above every file you want to debug in. Build yourself a function that prints nicely the information stored in $calls
.
class Debug {
private static $calls;
public static function log($message = null)
{
if(!is_array(self::$calls))
self::$calls = array();
$call = debug_backtrace(false);
$call = (isset($call[1]))?$call[1]:$call[0];
$call['message'] = $message;
array_push(self::$calls, $call);
}
}
每次在函数体中声明函数第一行时调用此函数:Debug::log($message(optional) )
Call this function everytime you declare a function first line in the functionbody: Debug::log($message(optional) )
这篇关于在PHP中获取被调用函数列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!