加载库后不同的$ this和& get_instance()

时间:2013-08-09 13:16:56

标签: php codeigniter

Windows中的

(Apache2 + PHP 5.2.9-2 + Codeigniter 2.1.4)

class Welcome extends CI_Controller {
    public function index()
    {
        $CI =& get_instance();
        echo $this === $CI; // echo 1
        exit;
    }
}

但是,

class Welcome extends CI_Controller {
    public function index()
    {
        $this->load->library('pagination');
        $CI =& get_instance();
        echo $this === $CI; // echo 0
        var_dump($this->pagination); // Undefined property: Welcome::$pagination
        exit;
    }
}

发生了什么事?

----------------添加--------------

codeigniter的控制器代码......

class A {
    protected static $instance;

    public function __construct()
    {
        self::$instance = &$this;
    }

    public static function &get_instance()
    {
        return self::$instance;
    }
}

class B extends A {
}

$b = new B();
$refA =  &A::get_instance();
$refA->a = 'aaa';
echo $b === $refA; // echo 0 in windows(php 5.2.17), 1 in Linux (php 5.2.17)

是这个错误吗?

0 个答案:

没有答案