Review PHP设计模式之——单例模式

时间:2023-06-05 19:32:50

单例模式:

 class Single {
private static $_instance; private function __construct(){
//define method as private
} public function __clone(){
trigger_error('Clone is not allow!', E_USER_ERROR);
} public static function getInstance(){
if(!(self::$_instance instanceof self)){
self::$_instance = new self;
}
return self::$_instance;
} public function show(){
phpinfo();
}
}
$single = Single::getInstance();
$single->show();