class Sigle{ private static $ins= null; //方法前加final 方法不能被覆盖,类前加final类不能被继承 final protected function __construct(){ } public static function getIns(){ if(self::$ins == null){ self::$ins = new self(); } return self::$ins; } //封闭clone final protected function __clone() { // TODO: Implement __clone() method. } } $s1 = Sigle::getIns(); //$s2 = Sigle::getIns(); $s2 =clone $s1; if($s1 ===$s2){ echo "一个对象"; }else{ echo "bushi"; }
单例
最新推荐文章于 2024-07-25 13:59:31 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)