roadhazzards
New Member
So, I am looking at a number of ways to store my configuration data. I believe I've narrowed it down to 3 ways:Just a simple variable\[code\]$config = array( "database" => array( "host" => "localhost", "user" => "root", "pass" => "", "database" => "test" ));echo $config['database']['host'];\[/code\]I think that this is just too mutable, where as the configuration options shouldn't be able to be changed.A Modified Standard Class\[code\]class stdDataClass { // Holds the Data in a Private Array, so it cannot be changed afterwards. private $data = http://stackoverflow.com/questions/2036140/array(); public function __construct($data) { // ...... $this->data = $data; // ..... } // Returns the Requested Key public function __get($key) { return $this->data[$key]; } // Throws an Error as you cannot change the data. public function __set($key, $value) { throw new Exception("Tried to Set Static Variable"); }}$config = new stdStaticClass($config_options);echo $config->database['host'];\[/code\]Basically, all it does is encapsulates the above array into an object, and makes sure that the object can not be changed. Or a Static Class\[code\] class AppConfig{ public static function getDatabaseInfo() { return array( "host" => "localhost", "user" => "root", "pass" => "", "database" => "test" ); } // .. etc ...}$config = AppConfig::getDatabaseInfo();echo $config['host'];\[/code\]This provides the ultimate immutability, but it also means that I would have to go in and manually edit the class whenever I wanted to change the data.Which of the above do you think would be best to store configuration options in? Or is there a better way?