Home  >  Article  >  Backend Development  >  关于include文件赋值的有关问题

关于include文件赋值的有关问题

WBOY
WBOYOriginal
2016-06-13 11:59:02948browse

关于include文件赋值的问题

<br />include文件:<br /><?php    <br />    $_CFG = array();<br />    $_CFG['DB_HOST'] = 'localhost';<br />    $_CFG['DB_USER'] = 'root';<br />    $_CFG['DB_PASWORD'] = 'liujianian';<br />    $_CFG['DB_NAME'] = 'commerceClub';<br />

<br /><?php<br /><br />class conf{<br />	protected static $ins = null;<br />	protected  $data = array();<br />	final protected function _construct(){<br />		//一次性将配置文件读取进来<br />		include('./config.php');<br />		$this->data = $_CFG;<br />	}<br />	final protected function _clone(){<br />	<br />	}<br />	public static function getIns(){<br />		if(self::$ins instanceof self){<br />			return self::$ins;<br />		}else{<br />			self::$ins = new self();<br />			return self::$ins;<br />		}<br />	}<br />}<br />$conf = conf::getIns();<br />print_r($conf);<br />

测试结果是:
conf Object ( [data:protected] => Array ( ) ) 
为什么数组$_CFG中的值没有被赋给全局变量protected   $data呢?
求解释
------解决方案--------------------
因为你漏掉了一个下划线
__construct
__clone

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn