<?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[0] = 100;
//$this->a[0] = 100;
$this->test();
print_r($this->a);
}
public function test()
{
$test = &$this->a;
$test[1] = 100;
}
}
$app = new App();
$test = new Test($app);
$test->p();
$app->p();
?>
php __get 函数一个隐藏问题
最新推荐文章于 2021-04-11 04:11:04 发布
本文通过一个PHP示例程序展示了如何使用引用传递对象属性,并解释了这种机制在修改类内部状态时的工作原理。代码示例包括两个类——App和Test,它们演示了如何通过引用更新数组元素。
130

被折叠的 条评论
为什么被折叠?



