Skip to content

Instantly share code, notes, and snippets.

@jamesBan
Forked from eddmann/dump.php
Last active September 16, 2015 08:09
Show Gist options
  • Save jamesBan/7a5a28aefca72e31a2fc to your computer and use it in GitHub Desktop.
Save jamesBan/7a5a28aefca72e31a2fc to your computer and use it in GitHub Desktop.
An alternative to 'var_dump'
function dump()
{
$args = func_get_args();
echo "\n<pre style=\"border:1px solid #ccc;padding:10px;margin:10px;font:14px courier;background:whitesmoke;display:block;border-radius:4px;\">\n";
$trace = debug_backtrace(false);
$offset = (@$trace[2]['function'] === 'dump_d') ? 2 : 0;
echo "<span style=\"color:red\">" . @$trace[1+$offset]['class'] . "</span>:" .
"<span style=\"color:blue;\">" . @$trace[1+$offset]['function'] . "</span>:" .
@$trace[0+$offset]['line'] . " " .
"<span style=\"color:green;\">" . @$trace[0+$offset]['file'] . "</span>\n";
if ( ! empty($args)) {
echo "\n";
call_user_func_array('var_dump', $args);
}
echo "</pre>\n";
}
function dump_d()
{
call_user_func_array('dump', func_get_args());
die();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment