Home >php教程 >php手册 >php单例模式笔记

php单例模式笔记

WBOY
WBOYOriginal
2016-05-26 08:21:031022browse

<?php   
	    class Db {   
	        private static $_db;//建立私有属性存放实例   
	        private function __construct(){//禁止类被实例   
	   
	        }   
	        private function __clone(){//禁止类被克隆   
	   
	        }   
	   
	        public static function getInstance(){//静态方法返回实例   
	            if(!(self::_db instanceof self)){//判定_db是否为自己的实例   
	                self::_db = new self;//不是就创建   
	            }   //phprm.com 
	            return self::_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