this is the main class of my project and I am using a array to store classes (not sure if this is the best way), but when using the line below...
$this->getController("config")->loadConfiguration();
It doesn't actually load the config? and when I access it in $this->classes instead of the getController function it says its empty?
I also get this error.. (EDIT) Fatal error: Call to a member function loadConfiguration() on a non-object
Here is my whole class:
<?php
defined("SECURE") or exit('Please define SECURE keyword to continue.');
class miracle
{
//Usage: $this->getController("test")->run();
private $classes;
public function __construct()
{
$classes = array();
}
public function run()
{
$this->loadClasses();
$this->getController("config")->loadConfiguration();
}
public function getController($c)
{
return $classes[$c];
}
private function loadClasses()
{
$this->classes["template"] = new template();
$this->classes["config"] = new config();
}
}
?>
loadConfiguration? (stick an echo/print in there, see what happens). If not, then the issue is that it doesn't call your function, and is not about your code not doing what's inside that function. If it does, then the problem is not about the class structure.$classesis in method scope.$this->classesis in class scope.this->classesisn't working. So you initialise it with content, and then check what it is inrun. You'd see it was empty, you reduce further, and go "oh wait, I forgot$this->in my contructor" probably followed by "did I do that anywhere else? oh I forgot it in getController too"