转自:PHP5与MySQL5web开发技术详解
<?php
class MyClass1
{
private $obj;
function __construct($obj)
{
$this->obj =$obj;
}
function __call($Method, $Args)
{
echo $Method."::".implode($Args, ',')."<br/>";
// 如果obj中有此方法,就 转调用obj中的方法
if (isset($this->obj) && method_exists($this->obj, $Method))
{
return call_user_func_array(array($this->obj, $Method), $Args);
// call_user_func_array("foobar", array("one", "two"));
}
}
}
class MyClass2
{
private $Num = 0;
function Add($Num1, $Num2)
{
$this->Num = $Num1 + $Num2;
return $this->Num;
}
}
$obj2 = new MyClass2();
$obj1 = new MyClass1($obj2);
echo $obj1->Add(2, 3);
?>
运行的结果
Add::2,3
5