// 工厂函数 // 自动加载一个类 class Example { public static function factory ($type) { if(include_once "./".$type.".php") { $classname = $type; return new $classname; } else { throw new Exception("file not find"); } } } $x = Example::factory("classOne"); $x->f();