当前位置:Gxlcms > PHP教程 > php单例模式

php单例模式

时间:2021-07-01 10:21:17 帮助过:13人阅读

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;

人气教程排行