Bird
0
0

Which of the following is the correct way for a child class constructor in PHP to invoke its parent class constructor?

easy📝 Conceptual Q2 of 15
PHP - Inheritance and Polymorphism
Which of the following is the correct way for a child class constructor in PHP to invoke its parent class constructor?
Asuper::__construct();
Bparent::construct();
Cparent::__construct();
Dthis->parent::__construct();
Step-by-Step Solution
Solution:
  1. Step 1: Identify the parent constructor call syntax

    In PHP, the parent constructor is called using parent::__construct().
  2. Step 2: Analyze each option

    parent::__construct(); uses the correct syntax. parent::construct(); uses an incorrect method name. super::__construct(); uses 'super' which is not valid in PHP. this->parent::__construct(); uses invalid syntax.
  3. Final Answer:

    parent::__construct(); -> Option C
  4. Quick Check:

    Correct parent constructor call syntax in PHP is parent::__construct(); [OK]
Quick Trick: Use parent::__construct() to call parent constructor [OK]
Common Mistakes:
  • Using 'super' instead of 'parent'
  • Omitting parentheses when calling parent constructor
  • Calling parent constructor as a property

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes