PHP Tutorial Traversal object Properties Two ways
/*
In this article we will provide you with two kinds of methods about traversing object properties, and illustrate the application of traversal object properties in PHP.
*/
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 ();
Method Two
class Foo {
Private $a;
public $b = 1;
Public $c = ' 111cn.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"]=>
111cn.net
}
Array (4) {
["A"]=>
Null
["B"]=>
Int (1)
["C"]=>
111cn.net
["D"]=>
Null
}
/*
It's easy to see the results above to traverse object properties.
*/
?>