class test{
static private $_instance;
public static function getInstance()
{
if(empty(self::$_instance))
{
self::$_instance =&$this;
}
return self::$_instance;
}
public function my()
{
echo 'mymy';
}
}
//$obj1,$obj2,$obj3相等
$obj1=test::getInstance();
$obj2=test::getInstance();
$obj3=test::getInstance();
$obj3->my();
弄不懂这里的&$this是什么意思。照理说$this表示对象的引用,再取地址表示个test对象在内存中的地址,再赋值给静态变量$_instance,这样$obj1,$obj2,$obj3应该都是一样的test对象了,应该可以调用my方法了,但实际报错。请大神指教下。
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
闭关修行中......