Questions about assigning an include file
Include file:
$_cfg = Array ();
$_cfg[' db_host ' = ' localhost ';
$_cfg[' db_user ' = ' root ';
$_cfg[' db_pasword '] = ' Liujianian ';
$_cfg[' db_name '] = ' commerceclub ';
Class conf{
protected static $ins = NULL;
protected $data = Array ();
Final protected function _construct () {
Read the configuration file in one go
Include ('./config.php ');
$this->data = $_cfg;
}
Final protected function _clone () {
}
public static function Getins () {
if (self:: $ins instanceof Self) {
Return self:: $ins;
}else{
Self:: $ins = new self ();
Return self:: $ins;
}
}
}
$conf = Conf::getins ();
Print_r ($conf);
The test results are:
Conf Object ([data:protected] = Array ())
Why is the value in array $_cfg not assigned to the global variable protected $data?
Ask for explanations
------Solution--------------------
Because you're missing an underscore.
__construct
__clone