function echo_parent_func() {
echo // so what now ?
}
function somefunc() {
echo_parent_func();
}
somefunc(); //should echo string 'somefunc'
甚至可以使用php吗?
答案 0 :(得分:2)
function get_caller_method()
{
$traces = debug_backtrace();
if (isset($traces[2]))
{
return $traces[2]['function'];
}
return null;
}
function echo_parent_func() {
echo get_caller_method();
}
function somefunc() {
echo_parent_func();
}
somefunc(); //should echo string 'somefunc'
编辑刚刚找到this answer: