标签:数据库连接
实用场景
| 编号 | 场景 |
| 1 | 数据库连接 |
| 2 |
<?php
/**
* PHP设计模式-单例模式
* @author chengtao3
*/
class Singleton{
private static $Instance = null;
/**
* 公共静态方法获取实例
* @return Singleton
*/
public function getInstance(){
if(self::$Instance == null){
self::$Instance = new Singleton();
}
return self::$Instance;
}
/**
* 屏蔽__clone方法,
* 单例模式,只有一个对象,如果使用了clone则可以复制,
* 因此屏蔽__clone方法
*/
public function __clone(){}
}本文出自 “程涛的博客” 博客,转载请与作者联系!
标签:数据库连接
原文地址:http://chengtao1633.blog.51cto.com/1340797/1431519