Created
October 10, 2016 16:03
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode 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