/**
* Class Singleton 单例模式
*/
class Singleton{
//私有静态属性
private static $instance;
//私有构造函数,防止new创建对象
private function __construct()
{
}
//防止对象被克隆
private function __clone()
{
// TODO: Implement __clone() method.
}
public static function getInstance() {
if (!(self::$instance instanceof self)) {
self::$instance = new self();
}
return self::$instance;
}
public function test()
{
echo '单例模式';
}
}