class A { //不允许类不直接实例化 或克隆 private function __construct(){} private function __clone(){} } class B { //不允许类不直接实例化 或克隆 private function __construct(){} private function __clone(){} } class Factory { public static function getInstance($class) { //类对象的获取方式通过工厂类 产生 return new $class(); } } $a = Factory::getInstance('A'); $b = Factory::getInstance('B');