对Controller中的一段源码困惑,请帮忙看看啊
小弟最近在看控制器实现源码中碰到下面这段,感觉很困惑,请各位帮忙一下在php4环境中,
在Controller的_ci_initialize函数中
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 中,有这么一段代码
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 这个是为何啊? 对呀。以前4的复制引用和5的复制引用不一样的哦!请看看php.net的在线手册。
页:
[1]