« 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); 

Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /homepages/36/d92845716/htdocs/ospinto/dbug/examples.php:154 Stack trace: #0 {main} thrown in /homepages/36/d92845716/htdocs/ospinto/dbug/examples.php on line 154