Let\'s face it, debug_backtrace()
output is not very pretty. Did anyone code a wrapper?
And what\'s your favourite pretty var_dump()
(which is
Here's a "pretty print" var_dump
function vdump() {
$args = func_get_args();
$backtrace = debug_backtrace();
$code = file($backtrace[0]['file']);
echo "";
echo "".htmlspecialchars(trim($code[$backtrace[0]['line']-1]))."\n";
echo "\n";
ob_start();
foreach ($args as $arg)
var_dump($arg);
$str = ob_get_contents();
ob_end_clean();
$str = preg_replace('/=>(\s+)/', ' => ', $str);
$str = preg_replace('/ => NULL/', ' → NULL', $str);
$str = preg_replace('/}\n(\s+)\[/', "}\n\n".'$1[', $str);
$str = preg_replace('/ (float|int)\((\-?[\d\.]+)\)/', " $1 $2", $str);
$str = preg_replace('/array\((\d+)\) {\s+}\n/', "array•$1 []", $str);
$str = preg_replace('/ string\((\d+)\) \"(.*)\"/', " str•$1 '$2'", $str);
$str = preg_replace('/\[\"(.+)\"\] => /', "'$1' → ", $str);
$str = preg_replace('/object\((\S+)\)#(\d+) \((\d+)\) {/', "obj•$2 $1[$3] {", $str);
$str = str_replace("bool(false)", "bool•false", $str);
$str = str_replace("bool(true)", "bool•true", $str);
echo $str;
echo "
";
echo "";
echo "Sizes: ";
foreach ($args as $k => $arg) {
if ($k > 0) echo ",";
echo count($arg);
}
echo "";
}