is it possible check if given function is executing within other function or method?
function echo_parent_func() {
echo // so what now ?
}
function somefunc() {
echo_parent_func();
}
开发者_JAVA百科
somefunc(); //should echo string 'somefunc'
Is that even possible with 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'
Source
EDIT Just found this answer too:
精彩评论