using the latest 0.5.0 release
Having configuration as a global variable is unwise and too easily screwed up.
Doing it as an associative array is also very brittle and vulnerable to typos.
Why not use a static class instead?
<?php
namespace GData;
class Options
{
public $use_objects = false;
// ... etc
static $o = null;
static function initialize()
{
$o = new self;
}
function __get($var)
{
throw new Exception('Unknown configuration option ' . $var);
}
function __set($var, $value)
{
throw new Exception('Unknown configuration option ' . $var);
}
}
Options::initialize();
// to access a config item, we do:
// $objects = Options::$o->use_objects;
?>
This would also allow easy replacement without having to do some weird file
manipulation.
<?php
class MyConfig extends GData\Options
{
public $use_objects = true;
}
Options::$o = new MyConfig;
You can still support loading of file to change options, with this kind of code:
<?php
namespace GData;
include $otherconfig;
foreach ($apiConfig as $key => $value) {
Options::$o->$key = $value;
}
?>
This would allow really easy tracking down of bugs because of a misspelled
option value, something that is impossible now because it simply fails silently
without changing the config value
Original issue reported on code.google.com by g...@chiaraquartet.net on 18 Jun 2012 at 9:07
Original issue reported on code.google.com by
g...@chiaraquartet.net
on 18 Jun 2012 at 9:07