var_dump is your friend! Forget about print_r!
We'll see in a bit, why!
Pros
- Easy to add to your code
- Fast way to check simple issues
- Gives detailed information on dumped variable
- Can also view complete objects/arrays
- Also provides type information
Cons
- No environment information
- Complex issues need lots of debugging code
- Dumping lots of variables gives lots of code
<?php
class Foo {
private $foo = "abc";
protected $bar = 100;
public $baz = "100";
}
echo "<pre>";
print_r( new Foo() );
var_dump(new Foo() );
var_dump( array( 1, 2, "foo" => "bar" ) );
echo "</pre>";
?>
Output
Foo Object ( [foo:Foo:private] => abc [bar:protected] => 100 [baz] => 100 ) object(Foo)#866 (3) { ["foo":"Foo":private]=> string(3) "abc" ["bar":protected]=> int(100) ["baz"]=> string(3) "100" } array(3) { [0]=> int(1) [1]=> int(2) ["foo"]=> string(3) "bar" }