子方法调用中的对象不完整


Incomplete Object in child method call

令人困惑的问题,想不出一个好的标题,但我会尽我所能解释。

我正在使用CodeIgniter,并利用get_instance()函数访问某些类中的CI超级对象。 我有一个调用超级对象的父类

abstract class parent{
/**
 * properties
 */
protected $CI;
/**
 * constructor
 */
public function __construct(){
    $this->CI =& get_instance();
}

和许多子类

class child extends parent{
    public function __construct(){
        //parent
        parent::__construct();
        print_r($this->CI);
    }
    public function doSomething(){
        print_r($this->CI);
    }
}

child构造函数中打印时,CI 对象很好。 在 child doSomething() 方法中打印时,我得到一个不完整的类对象。

编辑:

我相信我已经在某种程度上发现了问题。当 CI 创建其超级对象时,将使用控制器类。在我的问题出现的情况下,这是Login控制器。显然,当我通过引用分配时,该名称会延续,然后如果我不再在我的Login控制器中,则它存在不完整类的问题。我可以通过在使用它时重新调用 get_instance() 函数来"修复"它,但这不是一个很好的解决方案。有什么想法吗?

所以经过大量的寻找,我似乎在PHP手册中找到了答案

Warning
You can't use references in session variables as there is no feasible way to restore a reference to another variable.

这就是为什么它在许多地方都能正常工作的原因,但是如果我从$_SESSION变量访问它,例如我的登录用户,我会收到错误。它存储创建$_SESSION变量时的get_instance(),而不是我需要的引用。

感谢您的评论。