<?php
/*
*单列模式
*/
class odd
{
/*
*私有的构造方法
*/
private function __construct(){}
/*
*私有的静态变量
*/
private static $_instance = false;
/*
*私有克隆方法
*/
private function __clone(){}
/*
*公共的静态方法
*/
public static function getInstance()
{
if(self::$_instance===false)
{
self::$_instance = new self;
}
return self::$_instance;
}
public function Test()
{
return 123;
}
}
$sql = odd::getInstance();
echo $sql->Test();
简单的单列模式
最新推荐文章于 2022-03-16 16:05:36 发布