Developing software in the Real World

Runtime Variable Inspection

The most common way to debug is to stick echo statements into your code at strategic places. If you are feeling clever, you might even output a variable’s value too:

I call this runtime variable inspection and as PHP is a script language, it’s a very fast way to debug a script. You stick the echo statement at strategic points and with a few page refreshes in the browser, you have the troublesome bit of code nailed.

However echo $var doesn’t really cut it for variables or objects (or booleans for that matter). To this end I wrote myself a function called DBG() to print out a variety of variables sensibly.

The code looks like this:

It works wonders for fixing nearly all the bugs I have to deal with. Anything more complicated usually means that I break out the proper debugger in Zend Studio (wish they had a Firefox toolbar!)

Thoughts? Leave a reply

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