Skip to content

Instantly share code, notes, and snippets.

@arodu
Last active May 9, 2018 11:38
Show Gist options
  • Select an option

  • Save arodu/c3240f8e5e3a472badb6b168efce989a to your computer and use it in GitHub Desktop.

Select an option

Save arodu/c3240f8e5e3a472badb6b168efce989a to your computer and use it in GitHub Desktop.
Function debug in PHP
<?php
function debug($var, $return = false){
$trace = debug_backtrace();
foreach ($trace as $t) {
if($t['function'] == __FUNCTION__){
$file = $t['file'];
$line = $t['line'];
break;
}
}
$out = '<div class="debug">';
$out .= '<div class="file"><strong>'.$file.'</strong> (Line <strong>'.$line.'</strong>)</div>';
$out .= '<pre class="code">';
$out .= print_r($var, true);
$out .= '</pre>';
$out .= '</div>';
if($return){
return $out;
}else{
echo $out;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment