首頁 >後端開發 >php教程 >PHP-返射署理

PHP-返射署理

WBOY
WBOY原創
2016-06-13 11:43:14883瀏覽

PHP-返射代理

<?phpclass Personal {	public $name;	public $age;		function __construct() {		echo " __construct.. \r\n";	}		public function init() {		echo "init \r\n";	}}interface Work { 	function doWork($personal);} class Student extends Personal implements Work{	public function doWork($personal)  {		echo "$personal \n\r";	}}  # 代理 class ClassDelegator { 	private $target; 	 	function __construct($targetClass) { 		$this->target[] = new $targetClass(); 	} 	 	function __call($name, $args) { 		foreach ($this->target as $obj) { 			$r = new ReflectionClass($obj); 			if ($method = $r->getMethod($name)) { 				if ($method->isPublic() && !$method->isAbstract()) { 					return call_user_func_array(array(&$obj, $name), $args);				}			}		}  	} }  $stu = new ClassDelegator('Student'); $stu->doWork('1111', 'rerew');        

?

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn