<?php
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');
?>
php 反射機制實現代理模式
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.