<?php
/**
* 单例模式:确保某一个类只能有一个实例,通过私有属性,私有构造方法,私有克隆,公有静态方法(三私一公)开实现
* 应用场景:数据库的连接
*/
class Singleton
{
private static $instance = null;
private function __construct()
{
}
private function __clone()
{
}
public static function getInstance()
{
if (!self::$instance instanceof self) {
self::$instance = new self;
}
return self::$instance;
}
}