Source code:
[sourcecode language=‘php’]
class Constants { private $var_cache;
public function set($key, $val) { if(isset($this->var_cache[$key])) { throw(new Exception(“Constants->get() error: var $key has already been defined”)); } else { $this->var_cache[$key] = $val; } }
public function get($key) { return $this->var_cache[$key]; } } [/sourcecode] Example usage:
[sourcecode language=‘php’] $constants = new Constants();
$constants->set(‘base_url’, ‘www.domain.com/path');
…
$img_src_url = $constants->get(‘base_url’).’/img/file.jpg’;
echo “”;
[/sourcecode]