Skip to content

Instantly share code, notes, and snippets.

@radicaldingos
Created October 9, 2015 20:41
Show Gist options
  • Save radicaldingos/2913d9ed57cb82f75adc to your computer and use it in GitHub Desktop.
Save radicaldingos/2913d9ed57cb82f75adc to your computer and use it in GitHub Desktop.
Simple and useful debugging function
<?php
/**
* Fonction de débuggage
*
* Permet d'arrêter l'exécution du script et d'afficher le contenu d'une
* variable.
*
* @param mixed $objet Variable à afficher
* @param boolean $detail TRUE pour afficher un var_dump, FALSE pour print_r
* @param boolean $condition Condition à respecter pour arrêter le traitement
*/
function debug($objet = 'OK', $detail = false, $condition = true)
{
if ($condition) {
echo '<div style="background: ghostwhite; border: 2px solid steelblue; padding: 10px;">';
echo '<div style="float:right; font-family: Arial; margin: 0; padding: 0; color: grey; font-size: 11px;">Execution Time: ' . round(2, 2) . 's</div>';
echo '<h1 style="font-family: Arial; font-size: 16px; font-weight: bold; margin: 0; padding: 0; color: steelblue;">DEBUG</h1>';
echo '<pre>';
if (!$detail) {
if ($objet === null) {
echo 'null';
} else {
print_r($objet);
}
} else {
var_dump($objet);
}
echo '</pre>';
echo '</div>';
exit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment