PHP实例化对象单例的方法:

三私一公:2个私有方法,1个私有属性,1个公共方法

  private function __construct(){} //不可以继承构造方法

  private function __clone(){}//不可以继承克隆方法

  privare static $_instance;

一公

  public static function getinstance(){

    if(!isset(static:$_instance)){

      static::$_instance=new static();

      }

      return static::$_instance;

  }

内容来源于网络如有侵权请私信删除
你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!