Answer the question
In order to leave comments, you need to log in
How to stop creating class objects?
Hello, I decided to learn how to program at least a little in an adult way, and now .. I have a project in development, the following code is everywhere in the classes. I'm not comfortable that I have to create an object in __construct in order to use it in a class.
class TaskKey_Model
{
private $database;
private $user;
private $task;
public function __construct()
{
$this->database = new Database();
$this->user = new User_Model();
$this->task = new Task_Model();
..... и так далее
}
}
Answer the question
In order to leave comments, you need to log in
Obviously, Database() can be moved to a separate model, such as ActiveRecord,
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question