php的单例模式

复制代码
class DataBase
{
    private static $_instance;

    /**
     * 私有化构造方法,不能直接new对象
     * DataBase constructor.
     */
    private function __construct()
    {
    }

    /**
     * 私有化克隆方法,不能复制对象
     */
    private function __clone()
    {
    }

    /**
     * 此方法为唯一调用入口
     * @return DataBase
     */
    public static function getInstance()
    {
        if(!self::$_instance instanceof self)
        {
            self::$_instance = new self;
        }
        return self::$_instance;
    }
}
复制代码

 

posted @   zhou_blog  阅读(105)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示