I have 3 classes, engine, template, user. I connect the remaining 2 classes to the engine.

include_once 'model/template.php'; include_once 'model/user.php'; class Engine { public function __construct() { $this->tpl = new Template(); $this->user = new User(); } } 

And how would it be better to use the Template class in the User class? Is it even possible or not? Or is it necessary to reconnect the Template to User?

Update

I found only this solution:

 $this->user = new User($this->tpl); 

Just pass a variable to the class, and then in the User class use it as a local

 class User { function __construct($tpl) { $this->tpl = $tpl; } } 

I do not know how much this is right, maybe there will be better solutions.

  • one
    If you do a new User($this->tpl) then you don’t need to connect anything .. Only here the user probably shouldn’t know anything about any templates - Alexey Shimansky

0