Var_dump This function displays structure information about one or more expressions, including the type and value of the expression. The array recursively expands the value and displays its structure by indentation.
In this article we are going to provide you with two ways to iterate over object properties and illustrate the application of traversal object properties in PHP. You can see that private variables and static variables are not available, and can only be read if they are defined as public variables.
The first method of traversing object properties:
The code is as follows:
<?php class Foo {private $a, public $b = 1, public $c, private $d, static $e, public function test () {Var_dump (get_ob Ject_vars ($this)); }} $test = new Foo; Var_dump (Get_object_vars ($test)); $test->test ();?>
The results are as follows:
Array (2) {
["B"]=>
Int (1)
["C"]=>
Null
}
Array (4) {
["A"]=>
Null
["B"]=>
Int (1)
["C"]=>
Null
["D"]=>
Null
}
traversing Object Properties The second method:
The code is as follows:
<?php class Foo {private $a, public $b = 1, public $c = ' jb51.net ', private $d, static $e, public function test () {Var_ Dump (Get_object_vars ($this)); }} $test = new Foo; Var_dump (Get_object_vars ($test)); $test->test ();?>
The results are as follows:
Array (2) {
["B"]=>
Int (1)
["C"]=>
String (8) "Jb51.net"
}
Array (4) {
["A"]=>
Null
["B"]=>
Int (1)
["C"]=>
String (8) "Jb51.net"
["D"]=>
Null
}
var_dump Precautions for use:
To prevent the program from outputting the results directly to the browser, you can use the output control functions to capture the output of this function and save them to a variable such as a string type.
Var_dump Instance Code
The code is as follows:
<?php $a = Array (1, 2, Array ("A", "B", "C")), var_dump ($a);/* Output: Array (3) {[ 0]=> Int (1) [1]=> int (2) [2]=> Array (3) {[0]=> string (1) "A" [1]=> string (1) "B" [2]=> string (1) "C"} } */$b = 3.1; $c = TRUE; Var_dump ($b, $c); /* Output: Float (3.1) bool (TRUE) */;