Heim >Backend-Entwicklung >PHP-Tutorial >关于include文件赋值的问题

关于include文件赋值的问题

PHPz
PHPzOriginal
2016-06-23 13:55:551547Durchsuche

本文给大家介绍关于include文件赋值的问题,希望对需要的朋友有所帮助!

PHP实战教程https://www.php.cn/k.html

具体问题:

include文件:

<?php        
$_CFG = array();    
$_CFG[&#39;DB_HOST&#39;] = &#39;localhost&#39;;    
$_CFG[&#39;DB_USER&#39;] = &#39;root&#39;;    
$_CFG[&#39;DB_PASWORD&#39;] = &#39;liujianian&#39;;    
$_CFG[&#39;DB_NAME&#39;] = &#39;commerceClub&#39;;
<?php
class conf{ protected static $ins = null; 
protected  $data = array(); 
final protected function _construct(){ 
//一次性将配置文件读取进来 
include(&#39;./config.php&#39;); $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);

测试结果是:  

conf Object ( [data:protected] => Array ( ) )

为什么数组$_CFG中的值没有被赋给全局变量protected   $data呢? 

解决方案:

因为你漏掉了一个下划线 

__construct  
__clone
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn