1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
class test{ function callprint(){ print_r("onesdf"); } function test2( $args = "" ){ print_r( $args ); } }
class testDelegator{ private $targets; function __construct($obj){ $this->targets[] = $obj; } function __call($name,$args){ foreach($this->targets as $obj){ $r = new ReflectionClass($obj); if($method=$r->getMethod($name)){ if($method->isPublic() && !$method->isAbstract()){ return $method->invoke($obj,$args); } } } } }
$d = new testDelegator(new test()); $d->callprint(); $d->test2('the name of the method is test2','array2');
|