explain $ CI =& get_instance(); [英] explain $CI =& get_instance();

查看:205
本文介绍了explain $ CI =& get_instance();的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

查看代码igniters源代码,

looking through code igniters source code,

在它的帮助函数中我一直看到
$ CI =& get_instance();
任何人都可以向我解释这是如何工作的?

in its helper functions I keep seeing $CI =& get_instance(); can anyone please explain to me how this works?

我得到它返回一个引用$ CI super object,但是get_instance()是从哪里来的?

I get that it is returning a reference to the $CI super object, but where does get_instance() come from?

推荐答案

基本上是 Singleton设计模式使用函数而不是静态方法。

It's basically a Singleton Design Pattern that uses a function instead of a static method.

要更深入,请查看< a href =http://docs.gipertext.com/framework/ci170/d3/d9b/Base5_8php-source.html>源代码

所以基本上,它不强制单例,但它是一个公共函数的快捷方式...

So basically, it doesn't enforce the singleton, but it's a shortcut to a public function...

编辑:理解。对于PHP4兼容性,他们必须执行双全局变量hack 让它正确返回引用。否则,引用会得到所有的麻烦。并且由于PHP4没有支持静态方法(好吧,无论如何),使用函数是更好的方法。因此,由于遗留的原因它仍然存在...

Actually, now I understand. For PHP4 compatibility they had to do a double-global-variable-hack to get it to return the references properly. Otherwise the references would get all screwed up. And since PHP4 didn't have support for static methods (well, properly anyway), using the function was the better way. So it still exists for legacy reasons...

因此,如果你的应用程序只是PHP5,那么应该 $ c> CI_Base :: get_instance(); 而是,它是相同的...

So if your app is PHP5 only, there should be nothing wrong with doing CI_Base::get_instance(); instead, it's identical...

这篇关于explain $ CI =&amp; get_instance();的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆