What is inheritance in PHP?
Why Interviewers Ask This
This question tests conceptual clarity. Interviewers want to hear a precise, confident definition before moving to more complex PHP topics. It also reveals how well you can explain technical ideas to non-experts.
Answer
Inheritance in PHP allows a class to inherit properties and methods from a parent class using the extends keyword: class Dog extends Animal { }. The child class gets all public and protected members of the parent and can override them. PHP supports only single inheritance — a class can extend only one parent class. Use parent:: to call the parent class method or constructor: parent::__construct($name);. You can prevent a class from being extended by declaring it final. You can also prevent a specific method from being overridden by declaring it final. Traits compensate for the single-inheritance limitation by enabling horizontal code reuse.
Pro Tip
Back up your answer with a specific project or situation. Saying 'In my last PHP project, I used this when...' immediately makes your answer more credible and memorable.
Previous
What is the difference between public, protected, and private in PHP?
Next
What is an interface in PHP?