Home > Backend Development > PHP Tutorial > 关于include文件赋值的问题

关于include文件赋值的问题

PHPz
Release: 2021-03-23 10:37:15
Original
1503 people have browsed it

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

PHP实战教程//m.sbmmt.com/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;;
Copy after login
<?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);
Copy after login

测试结果是:

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

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

解决方案:

因为你漏掉了一个下划线

__construct  
__clone
Copy after login
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