Last active
May 11, 2016 08:26
-
-
Save Aleksandr-ru/c4e4807efba1eee36dd86f3e99a41248 to your computer and use it in GitHub Desktop.
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
<?php | |
/** | |
* pre() | |
* выводит обернутый в <pre>: print_r для массивов и объектов или var_dump для простых | |
* если включен error_reporting и display_errors | |
* | |
* @param mixed $expression | |
* @param bool $return | |
* @return bool || html | |
*/ | |
function pre($expression, $return = FALSE) | |
{ | |
if(error_reporting() && strtolower(ini_get('display_errors')) != 'off') { | |
ob_start(); | |
echo "<pre>"; | |
if(($callee = debug_backtrace()) && isset($callee[0])) echo "{$callee[0]['file']} line {$callee[0]['line']}: "; | |
if(is_array($expression) || is_object($expression) || is_resource($expression)) print_r($expression); | |
else var_dump($expression); | |
echo "</pre>"; | |
if($return) { | |
$ret = ob_get_contents(); | |
ob_end_clean(); | |
return $ret; | |
} | |
else { | |
ob_end_flush(); | |
return TRUE; | |
} | |
} | |
else return FALSE; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment