用户
 找回密码
 入住 CI 中国社区
搜索
查看: 2910|回复: 1
收起左侧

[控制器] 对Controller中的一段源码困惑,请帮忙看看啊

[复制链接]
发表于 2010-9-8 08:48:18 | 显示全部楼层 |阅读模式
小弟最近在看控制器实现源码中碰到下面这段,感觉很困惑,请各位帮忙一下
在php4环境中,
在Controller的_ci_initialize函数中
PHP复制代码
 
if (floor(phpversion()) >= 5)
                {
                        $this->load =& load_class('Loader');
                        $this->load->_ci_autoloader();
                }
                else
                {
                        $this->_ci_autoloader();
                       
                        // sync up the objects since PHP4 was working from a copy
                        foreach (array_keys(get_object_vars($this)) as $attribute)
                        {
                                if (is_object($this->$attribute))
                                {
                                        $this->load->$attribute =& $this->$attribute;
                                }
                        }
                }
 
复制代码

在Base4.php 中,有这么一段代码
PHP复制代码
 
function CI_Base()
        {
                // This allows syntax like $this->load->foo() to work
                parent::CI_Loader();
                $this->load =& $this;
               
                // This allows resources used within controller constructors to work
                global $OBJ;
                $OBJ = $this->load; // Do NOT use a reference.
         }
 
复制代码

所以小弟理解为:$this->load->$attribute =& $this->$attribute;中的 $this->load=& $this;是否是这样呢?
如果是这样的话,// sync up the objects since PHP4 was working from a copy 这个是为何啊?
发表于 2010-9-8 16:39:54 | 显示全部楼层
对呀。以前4的复制引用和5的复制引用不一样的哦!请看看php.net的在线手册。

本版积分规则