<?php class mysql { function connect($db) { echo "连接mysql数据库${db[0]} "; } } class oracle { function connect($db) { echo "连接oracle数据库${db[0]} "; } } class sqlproxy { private $target; function __construct($tar) { $this->target[] = new $tar(); } function __call($name, $args) { foreach ($this->target as $obj) { $r = new ReflectionClass($obj); if ($method = $r->getMethod($name)) {//获得类的反射方法 if ($method->isPublic() && !$method->isAbstract()) { $method->invoke($obj, $args);//调用对象的反射方法 } } } } } $mysql = new sqlproxy('mysql'); $mysql->connect('member'); $oracle = new sqlproxy('oracle'); $oracle->connect('member');