title: PHP - Require_once inside a class construct
body: <p>When I use <code>require_once</code> and try to access the variable within the required file I get an error that the variable (<code>$db</code>) is undefined.</p>
  
  <p>I have tried to place the <code>require_once</code> statement several diffrent places because I thought it might be variable scope issues, but at this point I try to call it within the constructor and the assign the value to a class variable. </p>
  
  <p>My config class:</p>
  
  <pre><code>class Config {
  
      public $db;
  
      public function __construct() {
          require_once (BASE_DIR."config/DBConfig.php");
          $this-&gt;db = $db;
      }
  }
  </code></pre>
  
  <p>The DBConfig file looks like this:</p>
  
  <pre><code>$db['default']['hostname'] = 'localhost'
  </code></pre>