Get name of caller function in PHP?

See debug_backtrace – this can trace your call stack all the way to the top.

Here’s how you’d get your caller:

$trace = debug_backtrace();
$caller = $trace[1];

echo "Called by {$caller['function']}";
if (isset($caller['class']))
    echo " in {$caller['class']}";

Leave a Comment