See what's going on inside your PHP variables!

download R45 for PHP5

changelog

Some examples:

<?php include 'debuglib.php'; # include debuglib at the first line in your script. Or load it through auto_prepend in your php.ini ?>
<?php DbugL::help(); ?>
print_a(mixed input [, string option_string])


The function you will use most often, prints a colorful representation of your PHP data

$option_string must be in the CSS like syntax:

e.g. "max_y:5;window:1;label:my_array"

If there is no ":" in the options string, the whole string will be used as the text for the label. new

Valid options:
return: (0|1) Do not print the output and instead return it as a string.
label: (string) Draw a fieldset/legend around the output.
max_y: (1-n) Maximum number of items on the same level. [...] (defaults to 50)
pickle: (0|1) Print a serialized representation of the array instead of printing it as a table.
export: (0|1) Print PHP sourcecode of the array. new
trim_tabs: (0-n) Trim the leading tabs in multiline strings and pad with n tabs.
window: (string) The output should open in a new window (javascript), the parameter is also the title for the window.
window_link: (0|1) Don't open a window, just print a link which opens one when clicked. new
debug_level: (0-99) Only do something if the debug level value is <= the global debug level ($GLOBALS['DEBUGLIB_LVL'] default 99) new
You can also set it to an array with the levels you want to display e.g. $GLOBALS['DEBUGLIB_LVL'] = array(3,5)
avoid@: (0|1) If a key starts with the character "@", assume it is a recursive reference and don't follow it.
mail: (string) Mail the ouput as HTML mail to the supplied email address. new
mail_encoding: (string) encoding for the HTML mail. (defaults to "utf-8")

You can also use these
short parameter names
trim_tabs
0tt
label
0l
max_y
0y
return
0r
window
0w
window_link
0wl
debug_level
0lvl
show_objects
0so
pickle
0p
mail
0m
mail_encoding
0me
escape_html
0e

show_vars([string option_string])


Prints all superglobals like $_GET, $_POST, $_SESSION etc. in a big table.
Good for printing at the bottom of a page.

Options are the same as for print_a + the following options:
verbose: also show $_SERVER and $_ENV

script_runtime([bool return_mode [, string title [, string css_style]]] )


Prints the passed time since the start of the script (or the last script_runtime call) in seconds.

pre(string string [, string option_string])


Print a string so the whitespaces are visible in HTML.

option_string must be in the CSS like syntax:

eg. "r:1;trim_tabs:0;"

Possible options:
return: (0|1) return the output instead of printing it
trim_tabs: (0-n) same as in print_a()

You can disable the output of all the functions in a production environment by setting $GLOBALS['USE_DEBUGLIB'] to FALSE (e.g. trough auto_prepend in your php.ini).

And if you have to do some online debugging you can enable it again somewhere in your script by setting it to TRUE.
<?php script_runtime("START", "background:green;color:white;"); ?>
[START] time: 0.002290
<?php print print_a($array, 'l:an array;r:1;tt:1'); ?>
an array
1eins
2zwei
3
011
11.2
2TRUE
3FALSE
4NULL
5''
6[]
4vier
5
band
nameRancid
members
Vocals, Guitar Tim Armstrong
Guitar, VocalsLars Frederiksen
Bass, VocalsMatt Freeman
Drums  Brett Reed
html   <div>
      <span>
         Chuck Norris does not sleep. He waits.
      </span>   
   </div>
6
first_var1
meeps1
sub_object
meeps1
7x
<?php print_a(1); ?>
(integer)1
<?php print_a($object1, 'some object'); ?>
some object
first_var1
meeps1
sub_object
meeps1
<?php print_a(' first <br />line '."\nsecond line", 'label:multiline string'); ?>
multiline string
(string) first <br />line
second line
<?php print_a(array(1,2,3,4,5,6), 'w:window1;max_y:2;label:blam!;'); # opens in a new window ?>
<?php print print_a($array, 'return:1;w:window1;'); # opens in a new window ?>
<?php print_a($array[5], 'w:window1;label:decode this pickled array with unserialize();pickle:1;'); # opens in a new window ?>
<?php print_a($array[5], 'w:window1;label:and now the php sourcecode for the same array;export:1;'); # opens in a new window ?>
<?php print_a($array[3], 'w:window2;label:window_link demo;window_link:1'); # click to open in a new window ?>
print_a( $array, w:window2;label:window_link demo;window_link:1 )
<?php print_a(array('a', 'b', 'c'), 'w:window3;'); # opens in a new window ?>
<?php script_runtime("right after opening window3"); ?>
[right after opening window3] time: 0.564822 (0.562532 since last call)
<?php print_a($html); ?>
(string)
      <div>
         <span>
            Chuck Norris does not sleep. He waits.
         </span>   
      </div>
   
<?php pre($html); ?>

      <div>
         <span>
            Chuck Norris does not sleep. He waits.
         </span>   
      </div>
   
<?php pre($html, 'trim_tabs:0;'); ?>
<div>
   <span>
      Chuck Norris does not sleep. He waits.
   </span>   
</div>
<?php show_vars('trim_tabs:0;show_objects:0;max_y:5;'); ?>
[before show_vars] time: 0.565857 (0.001035 since last call)
Script $GLOBALS
html<div>
   <span>
      Chuck Norris does not sleep. He waits.
   </span>   
</div>
array
1eins
2zwei
3
011
11.2
2TRUE
3FALSE
4NULL
...[2 skipped]
4vier
5
band
nameRancid
members
Vocals, Guitar Tim Armstrong
Guitar, VocalsLars Frederiksen
Bass, VocalsMatt Freeman
Drums  Brett Reed
...[3 skipped]
objectNULL
object1...
object2...
$_SESSION
a session variable
0spam
1eggs
vars in the background*eek* they see us! lets hide in the window name!
[after show_vars] time: 0.568517 (0.002660 since last call)
<?php print script_runtime("-FIN-", "background:red;color:white;",1); ?>
[-FIN-] time: 0.568589 (0.000072 since last call)