相关实例:
<?php
class a
{
function a($b)
{
$this->value=$b; //给a类$value赋值为:$b
$this->fun1=new b($this); //生成b类的对象,并且传给b类的值为a类这个结构
}
}
class b
{
function b(&$bb) //保证参数$bb传递要为地址传递模式
{
$this->fun2=&$bb; //b类$fun2接受a类这个结构
}
function echoValue()
{
echo "<br>","class ",get_class($this),': ',$this->fun2->value;
/*get_class($this):得到$this这个类的名字
$this->fun2为a类这个对象
$this->fun2->value为a类中value的值
*/
}
}
$foo=& new a("hello world!");
//保证$foo为引用生成的a类对象
$foo->fun1->echoValue();
?>