PHP单例模式self::$instance

PHP单例模式,单实例,不多说直接上代码

class Loswer {
    
    // $instance
    private static $instance = null;
    
    public function init() {
        echo 'lowser';
    }
    
    // instance
    public static function instance()
    {
        if (is_null(self::$instance)) {
            self::$instance = new self();
        }
        return self::$instance;
    }
    
}

 

 

© 版权声明
THE END

喜欢就支持一下吧

点赞10 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容