单例模式案例

Original 2019-06-06 14:07:16 196
abstract:<?phpclass Hubby{private function __construct() {}private function __clone() {}protected static $instance = null;public static function getInstance(){if(is_null(static::$instance)) {static::$instan

<?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)?'是':'不是';


Correcting teacher:查无此人Correction time:2019-06-10 09:09:56
Teacher's summary:完成的不错。编程有很多设计模式,多了解,对以后工作帮助很大。继续加油。

Release Notes

Popular Entries