【发布时间】:2011-07-03 17:57:12
【问题描述】:
function echo_parent_func() {
echo // so what now ?
}
function somefunc() {
echo_parent_func();
}
somefunc(); //should echo string 'somefunc'
用 php 也可以吗?
【问题讨论】:
function echo_parent_func() {
echo // so what now ?
}
function somefunc() {
echo_parent_func();
}
somefunc(); //should echo string 'somefunc'
用 php 也可以吗?
【问题讨论】:
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:
【讨论】:
false 作为参数调用debug_backtrace(对于PHP 5.3),这样会更快。