返回thinkph......登陆

thinkphp5.1中的单例模式

光棍叔2019-04-16 20:33:31379

//thinkphp5.1中的单例模式

class Demo

{

    private function __construct(){}

    private function __clone(){}

    protected static $instance=null;

    public static function getConnect(){

       if(is_null(static::$instance)){

           static::$instance=new static();

         }

        return static::$instance;

     }

}

$connect=Demo::getConnect();

最新手记推荐

• 用composer安装thinkphp框架的步骤• 省市区接口说明• 用thinkphp,后台新增栏目• 管理员添加编辑删除• 管理员添加编辑删除

全部回复(0)我要回复

暂无评论~
  • 取消回复发送