I have a hard time figuring out how to add a variable value to an instantiated class in php, I've been looking at the reflectionClass and tried to return an assigned variable, and now I'm ended up with a getter setter. I would really appreciate some help, here's an example of my code:
class controller
{
public $models;
private $load;
public function __construct()
{
$this->load = new loader();
}
public function action_being_run()
{
$this->load->set_model('model_name');
}
}
class loader
{
public function set_model($name)
{
{controller_class}->models[$name] = new model();
}
}
The controller class is instantiated without assigning it to a variable, but just:
new controller();
And then the action is executed from within the controller class.
controllerobject in the constructor of theloaderobject;$this->load = new loader($this);, etc.