PHP OOPLesson 48Free preview
PHP Inheritance
This lesson is part of PHP · All levels
Summary
Inheritance makes one class (child) inherit property and method from another class (parent) with keywords extends. Child can use the parent code as it is or replace it with the override method. PHP only supports single inheritance, which means that one class has only one parent class, but one parent can have many children.
Key points
- Extends are used by child classes to inherit parent members.
- The parent method can be override by defining the same method in the child.
- Parent::__construct() is used to run the parent constructor of child.
- Abstract and private members cannot be used as ordinary inheritance.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.