PHP 单例模式

来源:互联网 发布:美式家具 知乎 编辑:程序博客网 时间:2024/06/09 21:11
/*  config.class.php */<?phpclass conf{    protected static $inc = null;    protected $data = array();    public function __construct(){        include('./config.inc.php');        $this->data = $sql;    }    public static function getins(){        if(self::$inc instanceof self ){            return self::$inc;        }else{            self::$inc = new self();            return self::$inc;        }    }    public function __clone(){        exit('不能被复制');    }        public function test(){        echo 'ok';    }    }$conf = conf::getins();$conf->test();/* config.inc.php */<?php$sql = array(    'DBhost'=>'localhost',    'DBname'=>'root',    'DBpass'=>'');


0 0
原创粉丝点击