0

Is there any way (dirty is fine, this is only for debugging) to get the __FUNCTION__ (function name) from where a function was called from?

example;

function a() {
    //code
    return b();
}

function b() {
    return __PARENT_FUNCTION__
}

echo a();

This should yield a as the function name that was originally called for this output

Tom
  • 73
  • 1
  • 8
  • At the minute i'm just passing `__FUNCTION__` as a parameter to the 'child' function, it would be nice if I could do it automatically though – Tom Dec 16 '15 at 12:23

1 Answers1

2

Take a look at debug_backtrace

function a() {
    //code
    return b();
}

function b() {

    return debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)[0]["function"];
}

echo a();
jolmos
  • 1,565
  • 13
  • 25
  • 1
    Perfect, although I modified it slightly to `debug_backtrace()[1]['function'];` as it is in the [duplicate linked](http://stackoverflow.com/questions/2110732/how-to-get-name-of-calling-function-method-in-php) – Tom Dec 16 '15 at 12:35