Home  >  Article  >  Backend Development  >  PHP object instantiation singleton method

PHP object instantiation singleton method

高洛峰
高洛峰Original
2017-01-21 11:54:271341browse

PHP method of instantiating an object singleton:

Three private and one public: 2 private methods, 1 private property, 1 public method

private function __construct(){} //不可以继承构造方法
private function __clone(){}//不可以继承克隆方法
privare static $_instance;

一公

public static function getinstance(){
    if(!isset(static:$_instance)){
      static::$_instance=new static();
      }
      return static::$_instance;
  }

The above is the entire content of this article. I hope that the content of this article can bring some help to everyone's study or work. I also hope to support the PHP Chinese website!

For more articles related to PHP object instantiation singleton methods, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn