color = $color; $this->model = $model; } public function message() { return "我的车是一辆 " . $this->color . " " . $this->model . "!"; } } $myCar = new Car("red", "Volvo"); $myCar = (array) $myCar; var_dump($myCar);?>
对象转换为关联数组时,属性名变为键,属性值变为值。