Skip to content

Instantly share code, notes, and snippets.

@Krzysiu
Created October 10, 2016 16:03
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 Krzysiu/95b1ef9b77c7c98caf2c3c970fc547af to your computer and use it in GitHub Desktop.
Save Krzysiu/95b1ef9b77c7c98caf2c3c970fc547af to your computer and use it in GitHub Desktop.
Variation of var_dump which takes modifier as first parameter - PD::RETURN for returning value (default is echo), PD::PRE to contain dump in <pre>, PD::DIE to die() after run, PD::ESCAPE to escape HTML characters
class PD {
const RETURN = 1;
const PRE = 2;
const DIE = 4;
const ESCAPE = 8;
}
function pro_dump() {
if (func_num_args() < 2) return false;
$vars = func_get_args($vars);
$type = $vars[0];
unset($vars[0]);
ob_start();
foreach ($vars as $var) var_dump($var);
$result = ob_get_clean();
if ($type & PD::ESCAPE) $result = htmlspecialchars($result);
if ($type & PD::PRE) $result = "<pre>$result</pre>";
if ($type & PD::RETURN) return $result; else echo $result;
if ($type & PD::DIE) die();
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment