返回单例模式案例...登陆

单例模式案例

幸福敲门2019-06-06 14:07:16195

<?php

class Hubby

{

private function __construct() {}

private function __clone() {}


protected static $instance = null;

public static function getInstance()

{

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

static::$instance = new static();

}


return static::$instance;

}

}


$hubby1 = Hubby::getInstance();

$hubby1 = Hubby::getInstance();

echo ($hubby1 instanceof Hubby)?'是':'不是';

echo '<br>';

echo ($hubby2 instanceof Hubby)?'是':'不是';


最新手记推荐

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

全部回复(0)我要回复

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