亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

數(shù)據(jù)庫連接的單列模式案例

Original 2019-06-05 12:30:04 211
abstract:<?phpClass True_love{ private function __construct() {}    private function __clone() {}    protected static $instance = null;    public static fun

<?php
Class True_love
{
 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;
    }
}

$True_love1 = True_love::getInstance();
$True_love2 = True_love::getInstance();
echo ($True_love1 instanceof True_love)?'是':'不是';
echo '<br/>';
echo ($True_love2 instanceof True_love)?'是':'不是';
echo '<br/>';
echo ($True_love1 === $True_love2)?'完全相等':'不相等';
echo '<br/>';
var_dump($True_love1,$True_love2);


Correcting teacher:天蓬老師Correction time:2019-06-05 13:14:22
Teacher's summary:所謂單例, 就是唯一 實(shí)例, 它比全部采用靜態(tài)成員的方案, 要靈活

Release Notes

Popular Entries