Php 加载库后使用不同的$this和&get_instance()
在Windows Apache2+PHP 5.2.9-2+Codeigniter 2.1.4中Php 加载库后使用不同的$this和&get_instance(),php,codeigniter,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; } } 但是, 发生了什么事 --------增加------- codei
class Welcome extends CI_Controller {
public function index()
{
$CI =& get_instance();
echo $this === $CI; // echo 1
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)
这是一个错误吗?在这两种情况下我都得到了1。我使用XAMPP v3.0.12和php5.4.4测试了Windows 7 64位的更新代码,仍然得到1。@HashemQolami是的,我想问题发生在php5.2.x和Windows上
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)