Last active
November 27, 2017 16:19
-
-
Save peacefulseeker/a7cf76f03623cb92bec03fcd52825e36 to your computer and use it in GitHub Desktop.
PHP - Dumper by Koterov Dmitriy
This file contains 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 ## Функция для вывода содержимого переменной. | |
// Распечатывает дамп переменной на экран. | |
function dumper( $obj ) { | |
echo | |
"<pre>", | |
htmlspecialchars( dumperGet( $obj ) ), | |
"</pre>"; | |
} | |
// Возвращает строку - дамп значения переменной в древовидной форме | |
// (если это массив или объект). В переменной $leftSp хранится | |
// строка с пробелами, которая будет выводиться слева от текста. | |
function dumperGet( &$obj, $leftSp = "" ) { | |
if ( is_array( $obj ) ) { | |
$type = "Array[" . count( $obj ) . "]"; | |
} elseif ( is_object( $obj ) ) { | |
$type = "Object"; | |
} elseif ( gettype( $obj ) == "boolean" ) { | |
return $obj ? "true" : "false"; | |
} else { | |
return "\"$obj\""; | |
} | |
$buf = $type; | |
$leftSp .= " "; | |
for ( Reset( $obj ); list( $k, $v ) = each( $obj ); ) { | |
if ( $k === "GLOBALS" ) { | |
continue; | |
} | |
$buf .= "\n$leftSp$k => " . dumperGet( $v, $leftSp ); | |
} | |
return $buf; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment