On Wed, Jan 5, 2011 at 3:27 PM, Nathan Nobbe <quickshif...@gmail.com> wrote:

>  if($cachedConfig !== null)
>  {
>    // load file and store value(s) in $cachedConfig
>  }

"No config for you ... one year!"

Sorry, couldn't resist. :p

To expand on Nathan's excellent strategy, you could go one further and add
functions to config.php to return specific values from the config instead of
exposing the raw config object. This will have benefits if you change the
structure of the config later and only have to change your access code in
one place. It also replaces client code such as

    $config = load_config();
    if ($config['facebook']['enabled']) { ... }

with the more readable

    if (isFacebookEnabled()) { ... }

by adding an access function in config.php:

    function isFacebookEnabled() {
        $config = load_config();
        return (bool) $config['facebook']['enabled'];

You would still require_once 'config.php', but now you don't have to expose
knowledge of the config's internal structure to every script that needs to
access it.


Reply via email to