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

PHP object instantiation singleton method

高洛峰
Release: 2023-03-05 08:10:01
Original
1445 people have browsed it

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;
Copy after login

一公

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template