Recall & Review
beginner
What does the
parent keyword do in PHP?The <code>parent</code> keyword is used to access methods or properties from a parent class inside a child class.Click to reveal answer
beginner
How do you call a parent class constructor using <code>parent</code>?Inside the child class constructor, you call <code>parent::__construct()</code> to run the parent class constructor.Click to reveal answer
intermediate
Can
parent be used to access overridden methods?Yes, <code>parent</code> lets you call the parent class version of a method even if the child class has overridden it.Click to reveal answer
intermediate
What happens if you use <code>parent</code> in a class without a parent?Using <code>parent</code> in a class without a parent class causes a fatal error because there is no parent to refer to.Click to reveal answer
beginner
Example: How to call a parent method named
show() inside a child class?Use <code>parent::show();</code> inside the child class method to call the parent's <code>show()</code> method.Click to reveal answer
What does
parent::methodName() do in PHP?✗ Incorrect
parent::methodName() calls the method from the parent class, even if the child class has overridden it.How do you call the parent constructor inside a child class constructor?
✗ Incorrect
In PHP, the parent constructor is called with
parent::__construct().What error occurs if
parent is used in a class without a parent?✗ Incorrect
Using
parent in a class without a parent causes a fatal error because no parent exists.Can
parent access private properties of the parent class?✗ Incorrect
Private properties are not accessible by child classes, even with
parent.Which keyword is used to refer to the parent class in PHP?
✗ Incorrect
The keyword
parent is used to refer to the parent class in PHP.Explain how the
parent keyword works in PHP and give an example of calling a parent method.Think about how a child class can reuse code from its parent.
You got /3 concepts.
Describe what happens if you try to use
parent in a class that does not extend any other class.Consider what <code>parent</code> means and what happens if it has nothing to refer to.
You got /3 concepts.