Skip to content

Instantly share code, notes, and snippets.

@ivuorinen
Last active January 5, 2018 07:33
Show Gist options
  • Save ivuorinen/4344854 to your computer and use it in GitHub Desktop.
Save ivuorinen/4344854 to your computer and use it in GitHub Desktop.
debug() to aid in your development
<?php
/**
* debug
* a magical function to use in your code
*
* @author Ismo Vuorinen <https://github.com/ivuorinen>
*
* @param mixed $thing The thing you want to see
* @param bool $echo Should we return or echo the output [default: false]
* @param string $title If you need to mark your outputs
*
* @return mixed Uses var_export to get the data out
**/
function debug($thing = null, $echo = false, $title = '')
{
$export = var_export($thing, true);
if ($echo) {
echo sprintf("\n<pre>%s\n%s\n</pre>\n", $title, $export);
return true;
}
return $export;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment