这是我保存数据的类:
class AA{
public $a
public $b
private $_obj;
public function __constructor(){
}
public function populate(){
$data = //a query to get all data I need at once including $b
$this->a = $data->a;
$this->b = $data->b;
}
public function save() {
if ( $this->_obj instanceof BB ) {
$this->_obj->save() // $b is a value need to be manipulated in $_obj, it's saved there.
}
$data=array();// save all date excluding $b
update_data($data);
}
}
在填充 BB 类时,我不想对 $b 运行单独的查询,因为 AA 类中的查询已经获取了数据。如何将值传递给 BB 类?