0
我有一個Config類。每當'localhost'
在$_SERVER['HTTP_HOST']
,我想$ db_host是'localhost'
。默認情況下,它應該是'defaulthost'
;如何製作動態PHP類
class Config {
public static $db_username = 'username';
public static $db_password = 'password';
public static $db_database = 'database';
public function __construct() {
$host = 'defaulthost';
if(stristr($_SERVER['HTTP_HOST'],'localhost')){
$host = 'localhost';
};
self::$db_host = $host;
}
}
此代碼是給我一個錯誤
Fatal error: Access to undeclared static property: Config::$db_host in /Users/aakilfernandes/Dropbox/Projects/codeharmony/scripts/dev/v02/class/Database.php on line 98
所以......'公共靜態$ DB_HOST做;'應該解決這個問題了...... –