Debugging PHP - trace your steps
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!






+32 475 62.42.64
mick
2010-08-11 00:33