Inheritance in php

Inheritance in PHP

Inheritance is the php oops concept which is based around the concept of base classes or superclasses and derived classes or subclasses.

Base classes or Super Classes are also known as parent classes and similarly, derived classes or subclasses are known as child classes.

In the real world as a child take features from their parents, Same way in oops, child class inherit properties of their parent class with the help of inheritance.

We use `extends` keyword to implement inheritance in php.

Advantage of using inheritance in php oops, we can share properties of one class to other class.

In simple words Inheritance is When a class is defined by inheriting existing function of a parent class then it is called inheritance. Here child class will inherit all or few member functions and variables of a parent class.

Parent class − A class that is inherited from by another class. This is also called a base class or super class.

Child Class − A class that inherits from another class. This is also called a subclass or derived class.

Types of inheritance in PHP:

  • Inheritance has three type, single, multiple and multi level inheritance.
  • It supports only single inheritance, where only one class can be derived from single parent class.
  • We can simulate multiple inheritance by using interfaces.

For Example :

Scroll to Top