Mih*_*rga 14
最好的方法是加载它们,而不是通过外部文件包含它们
例如:
// config.php
$variableSet = array();
$variableSet['setting'] = 'value';
$variableSet['setting2'] = 'value2';
// Load config.php ...
include('config.php');
$myClass = new PHPClass($variableSet);
// In a class you can make a constructor
function __construct($variables){ // <- As this is autoloading, see http://php.net/__construct
$this->vars = $variables;
}
// And you can access them in the class via $this->vars array
Run Code Online (Sandbox Code Playgroud)