Introduction to Inheritance

Learn about inheritance and how to implement it in PHP.

What is inheritance?

Inheritance allows us to write code once in the parent class and then use it in both parent and child classes. One of the main advantages of object-oriented programming is its ability to reduce code duplication with inheritance. Code duplication occurs when a programmer writes the same code more than once. Using inheritance, we have a parent class with its own methods and properties and a child class (or classes) that can use the code from the parent class. By using inheritance, we can create a reusable piece of code that we write only once in the parent class and use again as much as we need to in the child classes.

Get hands-on with 1400+ tech skills courses.