当前位置:首页 > 前端 > 正文

php-单例模式

<?php
class sing {
    private static $instence = null;
    private function  __construct() {
    }
    private function __clone() {
    }
    public static function getinstence(){
        if (empty(self::$instence)) {
            self::$instence = new sing();
        }
        return self::$instence;
    }
}

懒汉式