I have an object which stores an app configuration in an associative array, as this:
[
'Database' =>
[
'DB_SERVER' => 'localhost'
'DB_NAME' => 'adbname'
'DB_USER' => 'theuser'
'DB_PASS' => 'thepass'
]
]
And a function, get(), which receives a variable number of arguments and returns the configuration value for this parameters. For example, Config::get('Database','DB_PASS')
will return 'thepass'.
This is an excerpt of the code:
class Config
{
protected static $values;
...
public static function get()
{
$val = &self::$values;
$argList = func_get_args();
for ($i = 0; $i < count($argList); $i++) {
$val = &$val[$argList[$i]];
if(empty($val)) break;
}
return (is_null($val)?"":$val);
}
}
Is there a more elegant / efficient way of accessing the value?