Chris Nizzardini

Salt Lake City, Utah Developer / Human / Blogger

Finding Out Where a Method is Being Called From in PHP

If you don’t have a debugger setup or would rather just see this sort of information in a log format use this snippet to find where a method is being called from. Note, if you have NetBeans configured with XDebug you can add a break point and watch the callstack for this sort of information.

$trace = debug_backtrace();
//$cache = "$key ".json_encode($value)." $duration";
$cache = '';
$caller = $trace[1]['file'].':'.$trace[1]['line'].' '.$cache;
error_log(__METHOD__.': '.$caller);

The output will go to where you apache error log is, typically /var/log/apache2/error.log:

[Tue Jun 26 17:29:22 2012] [error] [client 127.0.0.1] ApcEngine::write: /var/www/project/admin/config/bootstrap.php:173 , referer: http://localhost/page

Chris Nizzardini has been developing web applications since 2006. He lives and works in beautiful Salt Lake City, Utah. If you’re interested in hiring me for contract work please visit IO Spring LLC.

Twitter Google+ 

, ,

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>