创建可以从文件到文件使用的变量,甚至是对象到对象的最佳方式是什么?例如:PHP自定义全局变量
设置文件将包含一个这样的数组:如果你需要的是全球性的网站配置属性在所有PHPS
<?php
$config = array(
'key1' => 'val1',
'key2' => 'val2'
);
?>
<?php
class config {
function get_data($file){
require_once('config/'.$file.'.php');
foreach($config as $key => $val){
$this->$key = $val;
}
}
}
?>
它真的取决于变量的用法。您可以使用会话/ cookies/db存储等。请详细说明或使用变量。 – 2011-03-02 04:15:56
许多许多许多其他可能的重复[读写配置文件](http://stackoverflow.com/questions/2237291/reading-and-writing-configuration-files) – Gordon 2011-03-02 08:07:42