[php]代码库
class merge_objs{
private $classArr = array();
function __construct() {
$this -> classArr = func_get_args();
}
function __get($s) {
foreach($this-> classArr as $c) {
if (property_exists($c, $s)) {
return $c -> $s;
}
}
}
function __call($fn,$args) {
foreach($this-> classArr as $c) {
if (method_exists($c, $fn)) {
return call_user_func_array(array($c,$fn),$args);
}
}
}
}
//测试
class a1 {
public $a = 'a';
public function a() {
return 'a';
}
}
class b1 {
public $b = 'b';
public function b() {
return 'b';
}
}
class c1 {
public $c = 'c';
public function c() {
return 'c';
}
}
$m = new merge_objs(new a1(),new b1(),new c1());
var_dump($m->c); //c
var_dump($m->b); //b
var_dump($m->a); //a
var_dump($m->a()); //a
var_dump($m->b()); //b
var_dump($m->c()); //c