/* config.class.php */
<?php
class 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'=>''
);
PHP 单例模式
最新推荐文章于 2022-07-13 17:37:03 发布