Skip to content

Instantly share code, notes, and snippets.

@zettamax
Last active August 29, 2015 14:06
Show Gist options
  • Save zettamax/7c521d69ff615b21f338 to your computer and use it in GitHub Desktop.
Save zettamax/7c521d69ff615b21f338 to your computer and use it in GitHub Desktop.
Debug helper
<?php
declare(ticks=100);
register_tick_function('do_profile');
function do_profile() {
$bt = debug_backtrace();
if (count($bt) <= 1) {
return;
}
$frame = $bt[1];
unset($bt);
$type = $frame['type'];
$function = $frame['function'];
$class = $frame['class'];
$func = function ($a) {
if (is_array($a)) {
$count = count($a);
return "array(...) [$count]";
} elseif (is_string($a)) {
if (mb_strlen($a) > 30) {
$a = mb_substr($a, 0, 30) . '...';
}
return var_export($a, 1);
} else {
return var_export($a, 1);
}
};
$args = '(' . implode(', ', array_map($func, $frame['args'])) . ')';
error_log($class . $type . $function . $args . PHP_EOL);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment