Last active
December 12, 2015 10:59
-
-
Save yosugi/4762750 to your computer and use it in GitHub Desktop.
pretty print for PHP
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
/** | |
* pretty print for PHP | |
*/ | |
function pp($obj, $printer = 'var_dump') | |
{ | |
if (isset($_SERVER['REQUEST_METHOD'])) echo '<pre>' . PHP_EOL; | |
$bts = debug_backtrace(false); | |
$bt = array_shift($bts); | |
echo $bt['file'] . ':' . $bt['line'] . PHP_EOL; | |
call_user_func($printer, $obj); | |
if (isset($_SERVER['REQUEST_METHOD'])) echo '</pre>'; | |
echo PHP_EOL; | |
} | |
function pr($obj) | |
{ | |
pp($obj, 'print_r'); | |
} | |
function vd($obj) | |
{ | |
pp($obj, 'var_dump'); | |
} | |
function ve($obj) | |
{ | |
pp($obj, 'var_export'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment