Created
November 8, 2012 02:05
-
-
Save jasonrhodes/4036097 to your computer and use it in GitHub Desktop.
PHP print_r and die convenience
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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