title: Programming best practice for PHP configuration class and dependent classes
body: <p>I have an opportunity to rewrite a very large PHP application I wrote a year ago and I'm looking for feedback on an idea I had for implementing the application configuration.</p>
  
  <p>Currently I have a configuration class that reads my massive (and very human readable) <code>config.php</code> file that lets me access configuration parameters in the PHP code nicely and easily. This configuration object is instantiated as a variable in my <code>_init.php</code> script. A simplified sample is below:</p>
  
  <pre><code>&lt;?php
    class Configuration {
      public $someConfigProperty = true;
      public const someOtherConstant = false;
    }
  
    // _init.php
    $CONFIGURATION = new Configuration;
  ?&gt;
  </code></pre>
  
  <p>This works well, except that in every method of every other class I have to declare the <code>$CONFIGURATION</code> variable as a global. What I'd like to do instead is have every other class that needs to access the configuration object just extend the <code>Configuration</code> class. Something like this:</p>
  
  <pre><code>&lt;?php
    class Configuration {
      public $someConfigProperty = 'some string';
      public const someOtherConstant = false;
    }
  
    class Foo extends Configuration {
      public static function getConfigProperty() {
        return $this-&gt;someConfigProperty;
      }
    }
  ?&gt;
  </code></pre>
  
  <p><strong>My question is: is this a bad idea, and if so why? I'm looking for technical reasons why this shouldn't be done or concerns about future maintainability that would make this a bad idea.</strong></p>