Home > Backend Development > PHP Tutorial > PHP-返射署理

PHP-返射署理

WBOY
Release: 2016-06-13 12:30:54
Original
860 people have browsed it

PHP-返射代理

<?php class 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');
 
 
 
 
 
 
 
 
Copy after login

?

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template