1
類
我的代碼PHP OOP辛格爾頓
public static function constructMe() {
if(!$this->_instance instanceof self) {
$this->_instance = new self();
}
return $this->_instance;
}
要instansiate類,並且在類中的$_instance
變量,但我得到的錯誤:
Fatal error: Using $this when not in object context
是的,你可以做'新self();'。 – alexn 2011-06-10 21:24:21
是的,但如果它等於「蛋糕」或什麼的,那麼你知道..使用instanceof似乎更安全。 – Joshwaa 2011-06-10 21:25:10
如果它被設置爲「蛋糕」,你有更大的問題;) – Halcyon 2011-06-10 21:25:53