Blogger Information
Blog 21
fans 0
comment 0
visits 21210
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php单例类
星辰大海
Original
902 people have browsed it

单例模式有3个特点:

1.只能有一个实例。

2.必须自行创建这个实例。

3.必须给其他对象提供这一实例。

单例类举例:

class Example{

	private static $_instance = '';
	//防止被实例化
	private function __construct(){
	
	}
	
	static public function getInstance(){
		if(!self::$_instance){
			self::$_instance = new self();
		}
		retunr self::$_instance;
	}
	//防止被克隆
	private function __clone(){
	
	}

}


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post