Answer the question
In order to leave comments, you need to log in
What is the correct way to call a class inside another class?
There are two classes: 1 - responsible for registration, 2 - responsible for saving the message.
There is no binding reg, but I want to make it hidden. When requested to the server, classes are added by call, that is, one at a time (as if routing). As if all requests go to one page and are processed there. A specific class is connected to each request. When calling the second class without registration, the first class should be called using the same data.
Or is it stupid to do it right?
public function message($args) {
require 'firstclassfile.php';
$fco = new firstclassfile;
}
Answer the question
In order to leave comments, you need to log in
I would recommend reading about OOP. You are now trying to use a procedural approach.
In the case of classes, the code is not executed directly at the moment the file is included.
In your case, the MVC scheme is most likely implemented and the classes you are talking about are controllers.
I advise you to move the logic for saving the message and registering into separate modules and call them from the controller in the places where it is needed.
Simply including another controller will not help you.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question