Home >Backend Development >PHP Tutorial >dumprep.exe PHP var_dump function and application code for traversing object attributes
Below in this article, we will provide you with two methods of traversing object properties, and illustrate the application of traversing object properties in PHP. It can be seen that private variables and static variables cannot be obtained, and they can only be read when they are defined as public variables.
The first method of traversing object properties:
Copy the code The code is as follows:
class foo {
private $a;
public $b = 1;
public $c;
private $d;
static $e;
public function test() {
var_dump(get_object_vars($this));
}
}
$test = new foo;
var_dump(get_object_vars($test));
$test- >test();
?>
Copy code The code is as follows:
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();
?>
Copy code The code is as follows:
$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)
*/
?>
The above introduces the function and application code of dumprep.exe PHP var_dump to traverse object attributes, including the content of dumprep.exe. I hope it will be helpful to friends who are interested in PHP tutorials.