Debug PHP Function Calls

Logging errors can be very helpful as your code base becomes huge. But sometime it’s still difficult to find out what’s calling the function that’s giving the error. Wouldn’t it be nice if there was a way to see how you’d got to that function?

Well of course there’s a way in PHPdebug_backtrace. Just add something similar in a suitable place in your code and you’ll be able to find what functions were called.

$trace=debug_backtrace();
$caller = $trace[1]['function'];
// or just dump all the info
var_dump($trace);

Leave a Reply

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