class sigle{
protected static $ins = null;
public function getIns(){
if(self::$ins === null)
self::$ins = new self();
return self::$ins;
}
//方法不能被继承后修改,protected属性new不了
final protected function __construct(){
}
//不能被克隆
final protected function __clone(){
}
}
单例模式
最新推荐文章于 2024-03-17 23:07:06 发布