赞
踩
- <?php
- class Singleton
- {
- public $name;
- /********** Begin **********/
- /********** 1. 单例模式的类只能有一个实例,并由类自己创建(此处略) **********/
- public static $instance;
-
- /********** 2. 构造函数必须为私有 **********/
-
- private function __construct(){
- }
-
- /********** 3. 克隆函数必须为私有 **********/
- private function __clone(){
-
- }
- /********** 4. 必须提供一个静态的访问方法 **********/
- public static function getInstance()
- {
- if(!(self::$instance instanceof self)){
- self::$instance = new self();
- }
- return self::$instance;
- }
- /********** End **********/
- }

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。