php 单例模式
程序员文章站
2022-07-13 23:39:44
...
class DB{
static private $_instance;
public $name='name';
private function __construct(){
}
static public function getInstance(){
if(!(self::$_instance instanceof self)){
self::$_instance = new self();
}
return self::$_instance;
}
public function __clone(){
trigger_error('对象不允许被复制',E_USER_ERROR);
}
public function test(){
echo '调用方法成功';
}
}
//$db = new DB();
$db = DB::getInstance();
$db_clone = clone $db;
转载于:https://my.oschina.net/u/2411815/blog/650012
上一篇: Java中各种单例模式
下一篇: 几种单例模式