0

在 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)

这是错误吗?

4

0 回答 0