<?php
/**
* @note 懒汉式单例模式
*/
class Singleton{
//类实例
public static $instance;
public $a;
public static function getInstance()
{
if(!(self::$instance instanceof self)){
self::$instance = new self();
}
return self::$instance;
}
/**
* @note 私有化克隆方法防止克隆
*/
private function __clone()
{
}
}
$first = Singleton::getInstance();
//$first = new Singleton();
$second = Singleton::getInstance();
//$second = new Singleton();
//$first->a = '222222222222222';
//$second->a = 111111111111111;
echo '<pre>';
var_dump($first);
var_dump($second);