本文章下面我们要为你提供二种关于遍历对象属性方法,并且举例说明遍历对象属性在php中的应用.
- <?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();
-
-
-
- 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();
-
-
- array(2) {
- ["b"]=>
- int(1)
- ["c"]=>
- 111cn.net
- }
- array(4) {
- ["a"]=>
- NULL
- ["b"]=>
- int(1)
- ["c"]=>
- 111cn.net
- ["d"]=>
- NULL
- }
-
-
-
-
-
- ?>
|