class CI_Base { private static $instance; public function CI_Base()
{
self::$instance =& $this;
} public static function &get_instance()
{
return self::$instance;
}
}function &get_instance()
{
return CI_Base::get_instance();
}self::$instance =& $this;
请教一下 这句是 什么意思 ?
{
self::$instance =& $this;
} public static function &get_instance()
{
return self::$instance;
}
}function &get_instance()
{
return CI_Base::get_instance();
}self::$instance =& $this;
请教一下 这句是 什么意思 ?
php5中对象均以引用传递,声明为引用是多此一举,在特定的场合中还会报错这段代码本意是套用单例模式
但又不符合单例模式的规则本来 CI_Base::get_instance(); 应返回一个 CI_Base 类的实例,多次执行返回的都是同一个实例
但你的代码却要 先 new CI_Base 后 CI_Base::get_instance() 才生效
那再次 new CI_Base 不就发生冲突了吗?这样的代码,只会引导你进入歧途