Answer the question
In order to leave comments, you need to log in
Is it necessary to specify parent::__constructor in the class being extended if it exists in the parent?
I didn’t find this in the official documentation, but I read in some article that if the parent has a constructor, then if we need it in the extensible class , then we specify parent::__constructor.
And if not needed, is it necessary to specify parent::__constructor?
The matter is that it is not necessary to me, but the storm swears: there is no parent constructor.
Answer the question
In order to leave comments, you need to log in
If something is done in the parent's constructor, then it must be called from the child's constructor. If you do not call the parent constructor, then you must clearly understand what and why you are doing this.
class Constroller {
public function __construct() {
echo "Constroller-";
}
}
class Home extends Constroller {
public function __construct() {
echo "Home\n";
}
}
class About extends Constroller {
public function __construct() {
parent::__construct();
echo "About\n";
}
}
new Home();
new About();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question