Quentin Delcourt

A better view of the call stack in PHP

Whenever I want a quick overview of the call stack in PHP, I always find that debug_print_backtrace is a bad tool as it gives you way too much information.

I recently found the following trick on StackOverflow, which I think makes the call stack way more readable:

$e = new \Exception;

which gives you this kind of output:

#0 /home/qde/scripts/stack.php(12): A->a()
#1 /home/qde/scripts/stack.php(16): B->b()
#2 {main}

This way you can easily find out the path that led to a method call.

Thanks for the tip Tobias Cudnik!