Created
August 7, 2015 13:38
-
-
Save gettocat/a488bcdfe93d88718ba2 to your computer and use it in GitHub Desktop.
Debug function for clear php
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 | |
/** | |
* Подсвечивает результат var_dump | |
* @param mixed $var | |
* @return string dumpstr | |
*/ | |
function pd($var) { | |
ob_start(); | |
var_dump($var); | |
$v = ob_get_clean(); | |
$v = highlight_string("<?\n" . $v . '?>', true); | |
$v = preg_replace('/=>\s*<br\s*\/>\s*( )+/i', '=>' . "\t" . ' ', $v); | |
$v = '<div style="margin-bottom:5px;padding:10px;background-color:#fcfab6;border:1px solid #cc0000;">' . $v . '</div>'; | |
return $v; | |
} | |
/** | |
* Результат дампа переменных | |
*/ | |
function d() { | |
$arr = func_get_args(); | |
foreach ($arr as $var) { | |
echo pd($var); | |
} | |
} | |
/** | |
* Результат дампа переменных + die | |
*/ | |
function dd() { | |
$arr = func_get_args(); | |
call_user_func_array("d", $arr); | |
die; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment