获取PHP中调用方函数的名称? [英] Get name of caller function in PHP?
本文介绍了获取PHP中调用方函数的名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一个PHP函数可以找出给定函数中调用者函数的名称?
Is there a PHP function to find out the name of the caller function in a given function?
推荐答案
请参见 debug_backtrace -这可以一直跟踪您的调用堆栈.
See debug_backtrace - this can trace your call stack all the way to the top.
这是您如何吸引来电的方法:
Here's how you'd get your caller:
$trace = debug_backtrace();
$caller = $trace[1];
echo "Called by {$caller['function']}";
if (isset($caller['class']))
echo " in {$caller['class']}";
这篇关于获取PHP中调用方函数的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文