I apologise for the unclear title, I cannot think of any better one. I'm getting this error:
Fatal error: Call to a member function query() on a non-object
This is caused by the constructor in a class SPConfig
, which can be seen together with a class SPClasses
as follows:
$sp = new SPClasses();
class SPClasses
{
public $db, $config, $page, $users;
function __construct()
{
// The SPDatabase class [...]
$this->db = new SPDatabase();
// The SPConfig class [...]
$this->config = new SPConfig();
// [...]
// The SPTemplate class [...]
$this->page = new SPTemplate();
// The SPUsers class [...]
$this->users = new SPUsers();
}
}
class SPConfig
{
function __construct()
{
global $sp;
$configquery = $sp->db->query("SELECT * FROM config", 'Retrieving the configuration');
while($row = mysql_fetch_array($configquery))
{
try
{
$this->{$row['name']} = $row['value'];
}
catch (Exception $e)
{
$debug_log[] = array(
'type' => 'error',
'success' => false,
'text' => 'The config setting <i>' . $row['config_value'] . '</i> has an invalid name.'
);
}
}
}
public function update()
{
$this->__construct();
}
}
Does anyone know why it is impossible for me to access $sp->db
in the SPClasses
constructor?
Thanks.