qqruser 发表于 2017-4-2 12:39:19

php __get 函数一个隐藏问题

<?php
/**
* Copyright (c) 2009
* All rights reserved.
*
* 名    称:
* 摘    要:
* 版    本:1.0
* @author zhoudan
* @since 10.03.24 17:06:53
*/

class App{
public $a = array(1,2,3,4);
function &getA()
{
return $this->a;
}
function p()
{
print_r($this->a);
}
}
class Test{
private $app;
function __get($name)
{
if($name === "a")
{
$this->a = &$this->app->getA();
return $this->a;
}
}
public function __construct(App $app)
{
$this->app = $app;
}
public function p()
{
$a = &$this->a;
$a = 100;
//$this->a = 100;
$this->test();
print_r($this->a);
}
public function test()
{
$test = &$this->a;
$test = 100;
}
}
$app = new App();
$test = new Test($app);
$test->p();
$app->p();
?>
 
页: [1]
查看完整版本: php __get 函数一个隐藏问题