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

WBOY
Release: 2016-06-13 11:59:02
Original
973 people have browsed it

关于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 />
Copy after login

<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 />
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!