单例是因为一个就足够了,多了浪费
class TestClass {
private static $_instance;
public static function getInstance(){
if(!(self::$_instance instanceof self)){
self::$_instance = new self;
}
return self::$_instance;
}
}
实际中用作数据库连接类和工厂模式一起使用,根据参数调用单例模式,可以提高资源使用效率。