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