我有類PHP組數據
class User extends BaseModel{
public $id;
public $name;
}
class BaseModel{
function __construct($data=null){
if($data!=null)
//set $id and $name
}
}
我想設置的$ id,$名稱和通過調用
$test = new User(array('id'=>1,'name'=>'user name'))
擴展BaseModel任何其他數據我試圖用
$this->__set($arrayKey,$arrayValue);
但我得到的錯誤:致命錯誤:調用未定義的方法,用戶:: __集() 我在做什麼錯? 謝謝你的幫助。
可能重複[訪問對象,具有可變屬性?](http://stackoverflow.com/questions/7692162/access-object-attribute-with-variable) –