0
嘿傢伙我有一個問題,一類和單方法: 我使這個類蒙山的使用配置值內其他類的打算:單配置文件
<?
class Config {
public $values=array();
protected static $_instance = null;
//Getters
function __get($prop) {
return $this->values[$key];
}
//Setters
function __set($key, $value) {
$this->values[$key]=$value;
}
//Singleton
public static function getInstance() {
if (self::$_instance === null) {
$c = __CLASS__;
self::$_instance = new $c;
}
return self::$_instance;
}
}?>
我做一個實例蒙山的價值觀我連接如:
$config=new Config();
$config->conex=array(
'database' => 'lala',
'user' => 'lala',
'password' => 'lala',
'server' => 'localhost'
);
但是,當我打電話數據庫類內單方法的值都將丟失:
$config = Config::getInstance();
print_r($config->conex);
爲什麼是這個問題?
你不應該使用辛格爾頓 – dynamic