<?php
//单例模式
class Singleton {
    private static $instance=null;
    private $value=null;
    private function __construct($value) {
        $this->value = $value;
    }
    public static function getInstance() {
        //echo self::$instance."<br/>";
        if ( self::$instance == null ) {
            echo "<br>new<br>";
            self::$instance = new Singleton("values");
        } else {
            echo "<br>old<br>";
        }
        return self::$instance;
    }
}
$x = Singleton::getInstance();
var_dump($x); // returns the new object
$y = Singleton::getInstance();
var_dump($y); // returns the existing object
?>
        
     
    
        action
        本站未注明转载的文章均为原创,并采用
            CC BY-NC-SA 4.0授权协议,
            转载请注明来源,谢谢!如本站内容对你有所帮助的话,欢迎订阅关注
            邢栋博客,唠嗑(分享)每日的折腾经历。
     
 
已有 0 条评论