<?phpclass vardump{private static $isInLoop = false; private static $buffer = false; public static function dump () {$args = Func_get_args (); $args _num = Func_num_args (); if (self:: $buffer && $args _num = = 1) {$args = Func_get_args (); $args = isset ($args [0])? $args [0]: []; if (!empty ($args) && (Is_array ($args) | | is_object ($ARGS))) {$args _num = count ($args); }} Self:: $buffer = false; for ($i = 0; $i < $args _num; + + $i) {$param = $args [$i]; $ptype = GetType ($param); Switch ($ptype) {case ' NULL ': Self::d ump_null (); Break Case ' Boolean ': Self::d ump_boolean ($param); Break Case ' integer ': Self::d ump_integer ($param); Break Case "Double": Self::d ump_double ($param); Break Case ' string ': Self::d ump_string ($param); Break Case ' array ': Self::d ump_array ($param); Break Case ' object ': Self::d ump_object ($param); Break Case "resource": echo "resource"; Break Default:echo "Unknown type"; }}} public static function dumpx () {self:: $buffer = true; Ob_start (); Self::d UMP (Func_get_args ()); $var = Ob_get_clean (); return $var; public static function Dump_null () {echo "null"; if (!self:: $isInLoop) {echo "\ n"; } self:: $isInLoop = false; public static function Dump_boolean ($bool) {if ($bool) {echo "bool (true)";} else {echo "bool (false)"; } if (!self:: $isInLoop) {echo "\ n"; } self:: $isInLoop = false; public static function Dump_integer ($int) {echo "int ($int)"; if (!self:: $isInLoop) {echo "\ n"; } self:: $isInLoop = false; public static function Dump_double ($double) {echo "float ($double)"; if (!self:: $isInLoop) {echo "\ n"; } self:: $isInLoop = false; public static function Dump_string ($STR) {$len = strlen ($STR); $value = "string ($len) \" $str \ ""; Echo $value; if (!self:: $isInLoop) {echo "\ n"; } self:: $isInLoop = false; public static function Dump_array ($arr) {static $pads = []; $keys = Array_keys ($arr); $len = count ($arr); echo "Array ($len) {"; Array_push ($pads, ""); for ($i = 0; $i < $len; $i + +) {echo "\ n", Implode (", $pads)," [\ "$keys [$i]\"] + = "; $index = $keys [$i]; Self:: $isInLoop = true; Self::d UMP ($arr [$index]); } array_pop ($pads); $pad = Implode (' ', $pads); echo "\n{$pad}}"; if ($pad = = ") {echo ' \ n '; }} public static function Dump_prop ($obj) {static $pads = []; $reflect = new Reflectionclass ($obj); $prop = $reflect->getproperties (); $len = count ($prop); echo "($len) {"; Array_push ($pads, ""); for ($i = 0; $i < $len; $i + +) {$index = $i; if (! $prop [$index]->ispublic ()) {continue; } $prop _name = $prop [$index]->getname (); echo "\ n", implode (', $pads), "[\" {$prop _name}\ "] ="; Self:: $isInLoop = true; Self::d UMP ($prop [$index]->getvalue ($obj)); } array_pop ($pads); $pad = Implode (' ', $pads); Echo "\n{$pad}}"; if ($pad = = ") {echo ' \ n '; }} public static function Dump_object ($obj) {static $objId = 1; $className = Get_class ($obj); Echo "Object ($className) # $objId"; $objId + +; Self::d ump_prop ($obj); }}/* examples *///test string and integer$string = "I am a string"; $int = 1002; Vardump::d UMP ($string); Vardump::d UMP ($int),//test objectclass test1{public $var 1; public static $var 2 = ' var2 '; Private $var 3 = 333; function test () {echo "Test1 method"; }}class myclass{public $var 4 = 4444; Protected $var 5 = 55555; Public $test 1 = null; function __construct () {$this->test1 = new Test1 (); } function Test () {echo "MyClass method"; }}vardump::d UMP (new MyClass);//test array$arrtest = Array ("name" = "Jim", "courses" = = Array ("Phys ICS "=" 2016-2017 "," mathematics "= = Array (" Geometry "and" 2017-2018 ", "Algebraic" = "2015-2016",), "age" and "gender" = "male", "teacher" Array ("Physics" = "Lucy", "Geometry" = "Lilei", "algebraic" and "Russell",)); Echo Vard UMP::d umpx ($arrTest);//outputs:/*string () "I am a string" int (1002) object (MyClass) #1 (3) {["VAR4"] + int (4444) ["test1"] = = Object (test1) #2 (3) {["var1"] = NULL ["var2"] + string (4) "Var2"}}array (5) { ["name"] + = string (3) "Jim" ["courses"] = + Array (2) {["Physics"] + string (9) "2016-2017" ["Mat Hematics "] = = Array (2) {[" Geometry "] + = string (9)" 2017-2018 "[" algebraic "] = = string (9)" 2015-2016 "}} [" Age "] + int (+) [" gender "] = + string (4)" Male "[" teacher "] = + Array (3) { ["Physics"] = + string (4) "Lucy" ["Geometry"] = + string (5) "Lilei" ["algebraic"] and + string (7) "R Ussell "}}*/
PHP implementation Var_dump function