Is there a PHP function to find out the name of the caller function in a given function?
+4
A:
debug_backtrace() supplies details of parameters, function/method calls in the current call stack.
CMS
2008-10-10 07:37:20
+21
A:
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=array_shift($trace);
echo 'called by '.$caller['function']
if (isset($caller['class']))
echo 'in '.$caller['class'];
Paul Dixon
2008-10-10 07:37:32
It seems to me that this prints the callee function name. Use `list(, $caller) = debug_backtrace(false);` to get caller, `false` for performance ;-) (php5.3)
Znarkus
2010-02-17 22:17:30
+1
A:
You can extract this information from the array returned by debug_backtrace
Richard Turner
2008-10-10 07:38:43
A:
don't you need a semicolen after: echo 'called by '.$caller['function']
???
ed
2010-02-06 15:28:03
A:
Hi guys,
I've made a small extension for Zend_Log, now it shows class/method/line where logger was called from. See here http://mikebevz.com/2010/08/logger-with-caller-class-based-on-zend_log/
Mike Bevz
2010-08-03 07:52:50