Answer the question
In order to leave comments, you need to log in
What or how to replace the constructor?
There is a base controller class in the constructor of which the user's authorization is checked. There was a problem when creating child classes: If I create a new constructor in child classes, it overrides the base class constructor.
Why am I trying to use a constructor in child classes? - One example is the creation of a specific page model object.
Is it possible to somehow replace the constructor? Or maybe there is some other way?
Answer the question
In order to leave comments, you need to log in
class A {
public $firstname;
public function __construct($firstname) {
$this->firstname = $firstname;
}
}
class B extends A {
public $lastname;
public function __construct($firstname,$lastname) {
parent::__construct($firstname);
$this->lastname= $lastname;
}
}
$class = new B('Vasya','Pupkin');
echo $class->firstname , $class->lastname;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question