标签:pre tin log 共享 csharp static sel 访问 sharp
提供对自身共享示例的访问,限制特定对象只能被创建一次.
上面代理模式中同时也使用了单例模式.
class A{
    private static $instance = null;
    private function __contruct(){}
    public static getInstance()
    {
	if (is_null(self::$instance)) {
            self::$instance = new static(); //此处注意和new self的区别
        }
        return self::$instance;
    }
}
调用:
$a = A::getInstance();
$a->getInstance();
标签:pre tin log 共享 csharp static sel 访问 sharp
原文地址:http://www.cnblogs.com/itfenqing/p/7750608.html