Easy PHP Debugging
Wether I’m making complex web applications or a five page no brainer site, if I’m using PHP to do something the chances are something’s not going to work out exactly to plan. I quite often find myself spitting out this bit of code to see the contents of my variables: print_r($var);
While this works very well, it can be daunting to look at without some sort of formatting. Another dilemma I’ve found (only on those big projects) is that I can’t remember where I’ve put that piece of code in order to remove or comment it out.
Today I spent a short amount of time making my life easier. I’ve created a function that works very much the same way, but unlike print_r, this function can handle any type of variable. It’s extremely simple to use. Once the function is included to your application, just call it: echo dba($var1,$var2,$var3…);
The function will handle any amount of variables you throw at it. Here’s a sample output from one of my sites:
================================================================================
Debug Called:
/home/vhosts/trade/www/sub-contractors/materials.php on Line 448
/home/vhosts/trade/www/sub-contractors.php on Line 109
================================================================================
Argument #1: String
Hello World!
End Argument #1
================================================================================
Argument #2: Integer
9316729
End Argument #2
================================================================================
Argument #3: Float
4582.55
End Argument #3
================================================================================
Argument #4: Array
(
[0] => foo
[1] => bar
)
End Argument #4
================================================================================
Argument #5: db_mysql Object
(
[dbname:private] => trade
[id_link:private] => Resource id #15
[eh] =>
[query_counter] => 8
)
End Argument #5
================================================================================
Notice that the first part explains the trace of pages called before this function. On the first entry and line number you’ll find this function’s call. Subsequent pages are ‘parents’ of this page.

Hmmm… nice. I can see me using that one quite a bit. Expecially trying to debig my old programmer’s sloppy code! :p
I’m sure he wasn’t too sloppy with his typos though ;)
Oops…! :/
Okay, you win…