« Back to Home


How to use

Create an instance of the dBug class and pass in the variable for output.

1
2
include_once("dBug.php");
new 
dBug($myVariable); 

That simple. No need to access specific methods in the class.

NOTE: It's advisable to create a new instance of the dBug class each time you need to dump a variable. This ensures that all the public class variables are reset. This is really helpful especially when you are trying to dump xml variables.

1
2
new dBug($myVariable1);
new 
dBug($myVariable2); 

String
1
2
$variable "this is my string";
new 
dBug($variable); 
Output:
This is my string


Array
1
2
3
4
5
6
7
8
9
$variable = array(
    
"first"=>"1",
    
"second",
    
"third"=>array(
        
"inner third 1",
        
"inner third 2"=>"yeah"),
    
"fourth");

new 
dBug($variable); 
Output:
$variable (array)
first 1
0 second
third
array
0 inner third 1
inner third 2 yeah
1 fourth


Object
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class Vegetable {

   var 
$edible;
   var 
$color;

   function 
Vegetable($edible$color="green") {
       
$this->edible $edible;
       
$this->color $color;
   }

   function 
is_edible() {
       return 
$this->edible;
   }

   function 
what_color() {
       return 
$this->color;
   }
   
}
$variable=new Vegetable("spinach");
new 
dBug($variable); 
Output:
$variable (object)
edible spinach
color green
Vegetable [function]
is_edible [function]
what_color [function]


Database resource

When a database resource is dumped, mouse-overing the column names (example: ID, firstname,...) will display the database column type information in alt tags.

1
2
3
4
5
6
7
$link mysql_connect('localhost''mysql_user''mysql_password');
if (!
$link)
   die(
'Could not connect: ' mysql_error());

mysql_select_db('mydb');
$result mysql_query('select * from empinfo');
new 
dBug($result); 

Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host 'db74.perfora.net' (1) in /homepages/36/d92845716/htdocs/ospinto/dbug/examples.php on line 154

Warning: mysql_select_db() [function.mysql-select-db]: Can't connect to local MySQL server through socket '/tmp/mysqld.sock' (2) in /homepages/36/d92845716/htdocs/ospinto/dbug/examples.php on line 155

Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in /homepages/36/d92845716/htdocs/ospinto/dbug/examples.php on line 155

Warning: mysql_query() [function.mysql-query]: Can't connect to local MySQL server through socket '/tmp/mysqld.sock' (2) in /homepages/36/d92845716/htdocs/ospinto/dbug/examples.php on line 156

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /homepages/36/d92845716/htdocs/ospinto/dbug/examples.php on line 156
Output:
FALSE


XML Resource

When an xml variable is dumped as is, it is recognized as a string. This is even so with PHP's var_dump. The dBug class has a second optional parameter where you pass in the string "xml".

1
2
$xmlData "msc/data.xml"//path to xml file;
new dBug($xmlData"xml"); 
Output:
$xmlData,"xml" (xml document)
xmlRoot
xml element
xmlName chapter
xmlAttributes  
xmlText
xmlComment  
xmlChildren
xml element
xmlName TITLE
xmlAttributes  
xmlText This is my title
xmlComment  
xmlChildren
xml element
xmlName tgroup
xmlAttributes
array
cols 3
xmlText
xmlComment Another comment here on second line
xmlChildren
xml element
xmlName entry
xmlAttributes
array
morerows 1
xmlText b1
xmlComment  
xmlChildren