I have read almost all question I have found on StackOverflow on this topic, but could not find a straight answer.
Here is my code:
Application class
<?php
class Application extends Settings {
public function __construct($env, $cacheDir, $configFile) {
self::$_env = $env;
self::$_cacheDir = $cacheDir;
self::$_config = $this->loadConfig($configFile) // reads configs from xml file into Config object
}
// other methods
}
?>
Settings class:
<?php
class Settings {
protected static $_env = null;
protected static $_cacheDir = null;
protected static $_config = null;
public static function getEnv() {
return self::$_env;
}
public static function getCacheDir() {
return self::$_cacheDir;
}
public static function getConfig() {
return self::$_config;
}
}
?>
I access settings from anywhere in my code like this:
<?php
var_dump(Settings::getEnv());
?>
I want to access Settings form many different places. All values can be set only once and cannot be overwritten (so registry with __set methods do not work, because I can set any value from any place in any stage of application process)
Questions:
Is it good practice to store global settings like this. What downsides of this method? Maybe there's a much better way to do this?
Thank you for your answers