【发布时间】:2013-08-12 14:11:17
【问题描述】:
我将以下对象传递给函数:
$this->cars->car1->engine='v8';
$this->cars->car1->hp='330';
$this->cars->car2->engine='v6'
$this->cars->car1->hp='210';
handle_car($this->cars->car1);
handle_car(this->cars->car2);
函数handle_car需要找出它是什么车,即它是“car1”还是“car2”。
如何通过属性键查看属性是 car1 还是 car2?我曾尝试使用 get_object_vars 函数,但它只返回“car1”和“car2”的键,而不是它们本身。
【问题讨论】: