When I use require_once and try to access the variable within the required file I get an error that the variable ($db) is undefined.
I have tried to place the require_once 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.
My config class:
class Config {
public $db;
public function __construct() {
require_once (BASE_DIR."config/DBConfig.php");
$this->db = $db;
}
}
The DBConfig file looks like this:
$db['default']['hostname'] = 'localhost'
<?php?require_once. It requires only once. Hence the name. See as wellrequireand please add your "solution" as an answer below and accept it (well actually I'd say Luc Franken has the answer). Just setup what you need upfront before you use it and then you don't have these problems. And yes, Singleton is part of your problem, not the solution.