1
function echo_parent_func() {
    echo // so what now ?
}

function somefunc() {
    echo_parent_func();
}

somefunc(); //should echo string 'somefunc'

Is that even possible with php ?

rsk82
  • 28,217
  • 50
  • 150
  • 240
  • something similar: http://stackoverflow.com/questions/2960805/php-determine-where-function-was-called-from – tradyblix Jul 03 '11 at 09:56

1 Answers1

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'

Source

EDIT Just found this answer too:

Community
  • 1
  • 1
Gazler
  • 83,029
  • 18
  • 279
  • 245