In php, if A extends B, does B’s _constrctor() get executed automatically when A is instantiated? or do I have to call parent->_constructor()?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
PHP looks for the top-most (closest to the instantiated class)
__constructmethod it can find. It then executes that one only.And
parentaccesses the next one up the list until there are no more (at which point it’ll generate an error)…So, in class
E, runningparent::__construct()would execute classB‘s constructor.In class
B, runningparent::__construct()would execute classA‘s constructor.In class
A, runningparent::__construct()will generate an error since there is no constructor…