class Singleton
{
private static $instance;
private function __construct(){}
public static function getInstance()
{
if (null === static::$instance) {
static::$instance = new static();
}
return static::$instance;
}
private function __clone() {}
private function __wakeup() {}
}
$singleton = Singleton::getInstance();
PHP代码实现单例模式
最新推荐文章于 2024-10-10 21:56:19 发布