php单例模式

<?php
<?php
class sigle{
    protected static $ins = null;
    public static function getins(){
        if(self::$ins === null){
            self::$ins = new self();
        }
        return self::$ins;
    }
//方法千家final 则方法不能被覆盖,类前加final则类不能被继承
    final protected function __construct(){

    }
//封锁克隆
    final protected function __clone(){

    }
}
$s1 = sigle::getins();
$s2 = clone $s1;//报错

 

  

原文地址:https://www.cnblogs.com/sunlong88/p/8691478.html