0
我有下面的__set方法,它沒有被解僱。請注意方法頂部的echo '__set'
。當我打電話$class->__set(...);
而不是當我$class->title='whatever'
__set不叫
public function __set($name, $value){
echo '__set';
if($this->{$name}==$value) return;
switch($name){
case 'title':
case 'body':
case 'template':
case 'date':
case 'pageType':
if(!$this->exists()){
$this->DB->insert('posts', array($name, $value));
$this->ID=($this->DB->autoIncrement('posts')-1)<1?1:($this->DB->autoIncrement('posts')-1);
}
else{
$this->DB->update('posts', array($name => $value));
}
$this->{"$name"}=$value;
return;
break;
}
$this->{$name}=$value;
}
的方法工作正常。希望只是一個小錯或類似的東西,但在最近15分鐘內沒有發現它。
你有一個叫做$ title的屬性嗎?如果是這樣,那麼我很確定__set不會被調用。 – liquorvicar
僅當您試圖分配值的屬性不存在或無法訪問時,纔會調用__set。你確定你的班級沒有公共$ title屬性嗎? – rdlowrey