Stop using `global` in PHP

后端 未结 6 1935
醉梦人生
醉梦人生 2020-11-22 03:45

I have a config.php that is included to each page. In config I create an array that looks something like:

$config = array();
$config[\'site_name\         


        
6条回答
  •  盖世英雄少女心
    2020-11-22 04:40

    For your case I would create an only file constants.php with definitions (if your purpose is these "variables" never be changed in execution time):

    define('SITE_NAME','site name');
    
    define('BASE_PATH','/home/docs/public_html/');
    
    ...
    

    Include this constants.php in all files where you will need it:

    include_once('constants.php');
    

提交回复
热议问题