Skip to content

Instantly share code, notes, and snippets.

@yosugi
Last active December 12, 2015 10:59
Show Gist options
  • Save yosugi/4762750 to your computer and use it in GitHub Desktop.
Save yosugi/4762750 to your computer and use it in GitHub Desktop.
pretty print for PHP
/**
* 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