Manual

Debug-Var is a PHP class for sophisticated display of variables when developing scripts.
It offers similar information about variables as the PHP-functions "var_dump" or "var_export", but has more options and a much more improved grafical output!

Features

  1. Easily switch debug on and off.
  2. Display a summary with information about variable types, sizes and colorcoding for often used types as $_POST or $_SESSION.
  3. Display the variables highlighted and as valide PHP code.
  4. Easily define settings for the different display styles.

Have a look at the demo.

Usage

  1. Include the class. The only file you need is debug.inc.php. Copy it to a location that fits in your structure (e.g. your php include path).
  2. Instantiate the class object.
  3. Call the main method traceVar with the variablenames as parameters that you want to be displayed.

Examples

Example1. Simple usage
1.  <?php
2. 
include('_include/debug/debug.inc.php');
3. 
$myDebug = new Debug_Var(TRUE);
4. 
$myDebug->traceVar('$var1''$var2''var3');
5. 
?>

Make sure to set the first parameter for "Debug_Var" to [TRUE] (line 3). Otherwise the class will do nothing.
This parameter is an on-off-switch. Setting it to other value than [TRUE], will switch off whole Debug-Var.
This way you can easily shut down debugging, e.g. when you want to present your application to a customer.

Submit the names of the variables that you want to debug as parameters of the "traceVar" method (line 4). You can omit the "$".

Simple usage assumes, that variables are in the global scope. See Exaple 3 on how to trace variables from a local scope.

Example2. Optional parameters
1.  <?php
2. 
include('_include/debug/debug.inc.php');
3. 
4. 
$parameters = array
5. (
6. 
'outputType'  => 'direct'// direct or linked(default)
7. 
'showSummary' => TRUE,     // TRUE(default) or FALSE
8. 
'showVarType' => FALSE,    // TRUE(default) or FALSE
9. 
'showVarSize' => FALSE,    // TRUE(default) or FALSE or 'recursive'
10. 
);
11. 
12. 
$myDebug = new Debug_Var(TRUE$parameters);
13. 
$myDebug->traceVar('$var1''$var2''var3');
14. 
?>

You can define some optional parameters for the output.
Simply submit them in an array as the second parameter when initialising the Debug_Var class (lines 4-10 and line 12).

The following settings are available so far:

outputType
You can switch between 'direct' and 'linked' output.
Direct output will display all the requested variables right in your webpage (Sometimes your page then gets pretty long and ugly, e.g. when you trace large arrays of database queries...).
Linked output (which is the default value) will only display the summary. You can then klick on each summary item to display the variable or on the Debug-Var-marker (little red box) to open or close all displays of the requested variables. Linked output though will need to have javascript enabled in your browser (otherwise you can not open and close the displays).
showSummary
Can be [TRUE] or [FALSE]. If set to [FALSE] summary will not be displayed. If outpuType is set to 'linked' showSummary will automaticaly set to [TRUE] and usersettings will be overwriten. (Otherwise it would not display anything.)
showVarType
Can be [TRUE] or [FALSE]. If set to [TRUE] (which is default) abreviations of common variable types are displayed in the summary. Possible abreviations are:
  • arr = array
  • bool = boolean
  • float = float
  • int = integer
  • null = NULL
  • num = numeric
  • obj = object
  • res = resource
  • str = string
showVarSize
Can be [TRUE] or [FALSE] or 'recursive'. If it set to [TRUE] (which is default) sizes are displayed where possible in the summary. If set to 'recursive' sizes are displayed and arrays are counted recursively. If the variable is empty an E will be displayed.
Example3. Variables from local scope
1.  <?php
2. 
include('_include/debug/debug.inc.php');
3. 
$myDebug = new Debug_Var(TRUE);
4. 
5. function 
myfunc()
6. {
7.    
$myloc 'this is a local';
8.    
$myloc2 'this is another local';
9.    
$GLOBALS['myDebug']->traceVar(array('$myloc' => $myloc'myloc_nr2' => $myloc2));
10. }
11. 
12. 
myfunc();
13. 
?>

Apart from sending a variable's name to "traceVar" you can also send an array (line 9). In this case the array key will be displayed as the variable's name and the array value as its value. This is also the only possibility to check variables from within a local scope. You can of corse combine arrays and strings as parameters for the traceVar method.

Notices

You can find another good class for the same issue in PEAR

License

OSI certified

Debug-Var is OSI Certified Open Source Software
and is licensed under PHP License.

Copyright © 2005 by Viktor Grandgeorg
All rights reserved.
SourceForge.net LogoDebug-Var is a Project on
Sourceforge.net