PHP设计模式(一)单例

简单版

// trait 相当于代码片断,相当于复制粘贴代码
trait Singleton
{
    private static $instance;

    static function getInstance(...$args)
    {
        if (!isset(self::$instance)) {
            self::$instance = new static(...$args);
        }
        return self::$instance;
    }
}


发布了103 篇原创文章 · 获赞 81 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/yuhezheg/article/details/104127078