php 自定义配置文件

info.conf.php   //配置文件 

return array(
   'name' =>'dana',
   'address'=>'hunan'
);


// 配置类 
config.class.php

class Config
{
    protected static $config;
    
    // 加载配置文件
    function loadConf($confFile){

        if (is_file($confFile)){
             self::$config = include_once $confFile;
        }
    }

    function getConf($name){
        if(isset(self::$config[$name])){
            return self::$config[$name];
        }else{
            return " config $name is undefined ";
        }
    }


}


test.php  // 测试用例

require_once 'config.class.php';

$conf = new Config();

$conf->loadConf('info.conf.php');
print $conf->getConf('name');  //dana




 

猜你喜欢

转载自blog.csdn.net/zhouyuqi1/article/details/83753204