实用场景

<?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(){}
}