Development Wiki

PhpBB3.1/RFC/Config Class

From phpBB Development Wiki

Revision as of 08:43, 12 July 2011 by Igorw (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Encapsulate the global $config array in an object that can be passed around easily. This also improves unit testing because you can inject a custom config instance into the code you are testing. Also refactor set_config to be an instance method.


Because $config is a global variable, and set_config is a global function, it is very difficult to unit test anything that relies on them.



Read a configuration value.

$version $config['mymod_version'];


phpbb_config::set($key, $value, $cache = true)

Set a configuration option's value.



phpbb_config::increment($key, $increment, $cache = true)

Increments an integer configuration value.



The new config classes make use of the new cache drivers. A driver is injected into the config class. There are two implementations of config. One array-based one (for tests) and a db-based one which provides persistence.

This feature is almost fully backwards-compatible. phpbb_config implements ArrayAccess, allowing it to be accessed as if it were an array. set_config and set_config_count are initialized with a config instance which is cached in a static variable. Use of these functions is deprecated however, new code should use the instance methods of the config object.

It makes use of autoloading.