Skip to content

Instantly share code, notes, and snippets.

@jasonrhodes
Created November 8, 2012 02:05
Show Gist options
  • Save jasonrhodes/4036097 to your computer and use it in GitHub Desktop.
Save jasonrhodes/4036097 to your computer and use it in GitHub Desktop.
PHP print_r and die convenience
<?php
function debugout($value, $autodump = false)
{
if ($autodump || (empty($value) && $value !== 0 && $value !== "0") || $value === true) {
var_dump($value);
} else {
print_r($value);
}
die();
}
class Testy
{
public $thing = "thing";
protected $other = "secret";
}
debugout(new Testy()); # => Testy Object ( [thing] => thing [other:protected] => secret )
debugout(array(
"candy" => "twix",
"name" => "bob")
); # => Array ( [candy] => twix [name] => bob )
debugout("word stuff!"); # => word stuff!
debugout(5); # => 5
debugout(0); # => 0
debugout("0"); # => 0
debugout("0", true); # => string(1) "0"
debugout(null); # => NULL
debugout(false); # => bool(false)
debugout(true); # => bool(true)
echo "You didn't die! Oh no!";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment