案例:PHP案例     状态:不可编辑再运行    进入竖版
 运行结果 
x
 
1
<?php
2
class Car
3
{
4
    var $color;
5
    function Car($color="green") {
6
      $this->color = $color;
7
    }
8
    function what_color() {
9
      return $this->color;
10
    }
11
}
12
13
function print_vars($obj) {
14
   foreach (get_object_vars($obj) as $prop => $val) {
15
     echo "\t$prop = $val\n";
16
   }
17
}
18
19
// instantiate one object
20
$herbie = new Car("white");
21
22
// show herbie properties
23
echo "\herbie: Properties\n";
24
print_vars($herbie);
25
26
?>