Skip to content

Instantly share code, notes, and snippets.

@Sirpyerre
Last active November 14, 2017 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sirpyerre/e3fffe191cef9cc28ec0b6cc2b057691 to your computer and use it in GitHub Desktop.
Save Sirpyerre/e3fffe191cef9cc28ec0b6cc2b057691 to your computer and use it in GitHub Desktop.
Una función para debuguear el contenido de una variable
<?php
function dd( $array = array(),$message = '', $exit = true)
{
$trace = debug_backtrace();
$file = isset($trace[0]['file']) ? $trace[0]['file'] : 'Unknow';
$line = isset($trace[0]['line']) ? $trace[0]['line'] : 'Unknow';
$class = isset($trace[1]['class']) ? $trace[1]['class'] : '';
$function = isset($trace[1]['function']) ? $trace[1]['function'] : '';
if (is_array($array)) {
echo '<pre>*************<b>' . $message . '</b>***************<br>';
echo '<p style="color:red">';
print_r($array);
echo '</p>';
echo '</pre>';
if (!empty($class)) {
echo '=========&gt; ' . $class . '::' . $function . '&lt;=========<br>';
}
} else if (is_object($array)) {
echo "=========&gt; $message &lt;=========";
var_dump($array);
echo " &lt;=========";
if (!empty($class)) {
echo '=========&gt; ' . $class . '::' . $function . '&lt;=========<br>';
}
} else {
echo "=========&gt; $message &lt;=========";
var_dump($array);
echo " &lt;=========";
}
echo 'Line[' . $line . '], in file ' . $file .'&lt;=========<br>';
if ($exit) {
exit();
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment