Skip to content

Instantly share code, notes, and snippets.

@gbrock
Last active August 29, 2015 14:10
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 gbrock/17b2d9b3d31b17aebab3 to your computer and use it in GitHub Desktop.
Save gbrock/17b2d9b3d31b17aebab3 to your computer and use it in GitHub Desktop.
A function to output variables on-screen for debugging purposes.
<?php
/**
* output whatever variable is passed on-screen for debugging purposes
*
* @param mixed $oVar the variable to be debugged
* @param bool $bContinue if false, sends a full-stop to the running script
* @return void
*
* @author gBrock
* @license http://creativecommons.org/publicdomain/zero/1.0/ Public Domain
*/
if(!function_exists('debug'))
{
function debug($oVar = NULL, $bContinue = FALSE)
{
echo '<pre>';
switch(TRUE)
{
case $oVar === FALSE:
echo 'FALSE (bool)'; // Boolean, FALSE
break;
case $oVar === TRUE:
echo 'TRUE (bool)'; // Boolean, TRUE
break;
case $oVar === NULL:
echo 'NULL (empty)'; // NULL value
break;
case is_string($oVar) && $oVar === '':
echo '""'; // empty string
break;
case is_string($oVar):
echo $oVar; // a regular string
break;
default:
print_r($oVar); // anything else
break;
}
echo '</pre>';
if(!$bContinue)
{
// Set the header so output looks correct in-browser
header('Content-Type: text/html; charset=UTF-8');
exit;
}
}
}
@gbrock
Copy link
Author

gbrock commented Dec 16, 2014

Perhaps more aptly-named "dump()".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment