Amazium bvba, your online partner
Debugging PHP - trace your steps
  • Share post with Twitter
  • Share post with StumbleUpon
  • Share post with Delicious
  • Share post with Digg
  • Share post with Technorati
  • Share post with Blinklist
2009-12-18 16:37

Debugging PHP - trace your steps

trace, debug

Often when you need to debug an application, especially one with multiple classes calling each other, it is difficult to spot where the problem lies.

When an exception is thrown, you get a stack trace and you can drill down to a problem. Fatal errors, notices, warnings,... don't give you that unfortunately. Luckily for us, there is are 2 php functions available that does allow us to trace or steps: debug_backtrace and debug_print_backtrace.

debug_backtrace generates a PHP backtrace and returns it as an array. debug_print_backtrace prints a PHP backtrace including the function calls, included/required files and eval()ed stuff:

#0 eval() called at [/tmp/include.php:5]
#1 a() called at [/tmp/include.php:17]
#2 include(/tmp/include.php) called at [/tmp/test.php:3]

#0 c() called at [/tmp/include.php:10]
#1 b() called at [/tmp/include.php:6]
#2 a() called at [/tmp/include.php:17]
#3 include(/tmp/include.php) called at [/tmp/test.php:3]

Enjoy and happy debugging!

Comments and Feedback
tata

Add a Comment

Your email is never published or shared. Required fields are marked*