话不多说直接上代码 talk is cheap show you the code!
<?php
class Singleton {
private static $_instance = null;
private function __construct() {
}
public static function getInstance() {
if (is_null(self
::$_instance)) {
self
::$_instance = new self();
}
return self
::$_instance;
}
public function __clone() {
die("单例模式不能克隆");
}
}
获取我们的实例
<?php
Singleton
::getInstance();
转载请注明原文地址: https://mac.8miu.com/read-485723.html