我有一個類的方法__toString和__get和一些受保護的屬性,如「消息」。到現在爲止還挺好。PHP分段錯誤| __get在類內部調用受保護的屬性?
現在的問題是,我需要訪問__toString中的$ this->消息,並且當$ display_all被設置爲true時,這會導致(並非總是失敗)分段錯誤。你知道爲什麼以及如何解決它嗎?
非常感謝! 羅爾夫
PS:這裏是一個例子
class FuckedClass {
protected $file;
protected $line;
protected $display_all;
protected $message;
//[...]
/**
* Magic getter
* @param String $name
* @return mixed
*/
public function __get($name) {
return (in_array($name,array_keys(get_class_vars(__CLASS__))))?
$this->$name : null;
}
/**
* Formats
*/
public function __toString() {
$message = $this->message . ($this->display_all) ?
'[ Location: '.$this->file.' @ line '.$this->line.' ]':
'';
$text =<<<PLAIN
Error : {$message}
PLAIN;
return $text;
}
}
//instantiated $fucked_class
die($fucked_class);
你可以發佈一個簡短的腳本來舉例說明問題嗎? – Artefacto 2010-06-23 14:46:02
hi Artefacto,done;) – Rolf 2010-06-23 14:55:01
@Rolf Works罰款這裏:http://codepad.viper-7.com/qzOJNL嘗試更新PHP – Artefacto 2010-06-23 15:14:10