Debugging

If do a lot of php work like I do, there’s no substitute for the classic echo ‘here’; statement whilst debugging. In recent years though i’ve tried to be a bit more creative.

Quite recently I stumbled across debug_backtrace(), a very useful little function. It’s basically print_r style dump with a lot more info. I use it in my own little debugging routine which throws out an email with the following structure.

$report =
print_r($_SERVER,TRUE).”\n\n”.
print_r($_REQUEST,TRUE).”\n\n”.
print_r(debug_backtrace(),TRUE);

If you use a lot of requires/includes in your application this can be very useful in tracing back to the start of what actually triggered the problem.

Hope you all find it useful.

No tag for this post.

One Response to “Debugging”

  1. Steven Jackson Says:

    Very useful Gary. I’ve just tended to use strategically place echos, but I’ll have to give print_r and debug_backtrace a try.

Leave a Reply

Entries (RSS)