Home  >  Article  >  Backend Development  >  php 单例模式

php 单例模式

WBOY
WBOYOriginal
2016-06-20 12:33:08793browse

class DB{		static private $_instance;		public $name='name';		private function __construct(){		}		static public function getInstance(){			if(!(self::$_instance instanceof self)){				self::$_instance = new self();			}			return self::$_instance;		}				public function __clone(){			trigger_error('对象不允许被复制',E_USER_ERROR);		}		public function test(){			echo '调用方法成功';		}	}	//$db = new DB();	$db = DB::getInstance();	$db_clone = clone $db;


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