Easy To Learning
  • Login
  • Sign Up
  • Q&A
  • Home
  • Php Tutorial
  • MySql Tutorial
  • Object-Oriented Programming
  • Java Tutorial
  • HTML Tutorial
  • React JS Tutorials
  • Free Projects
  • Blogs & Articles
  • Others
    • About Us
    • Contact Us
Inheritance in PHP
Easy To Learning

Education Needs Complete Solution

Online Ask Question Question And Answer
  1. Home
  2. PHP Object Oriented Tutorials
  3. Inheritance in PHP

PHP Object Oriented Tutorial

Basic Object Oriented Tutorials

  • Object Oriented Programming In PHP
  • Advantage of OOPS In PHP
  • Important OOPS concepts
  • Oops Features In PHP
  • Class In PHP
  • Object In PHP
  • Constructor and Destructor
  • Inheritance in PHP
  • Encapsulation In Php
  • Abstract Classes In PHP
  • Interface In PHP
  • Polymorphism In Php

Inheritance in PHP

When the properties and the methods of the parent class are accessed by the child class, we call the concept has an inheritance. The child class can inherit the parent method and give its own method implementation, this property is called the overridden method. When the same method of the parent class is inherited we call it as an inherited method. Now let us see types of inheritance supported in Object Oriented Programming and corresponding Php inheritance examples.

Types Of Inheritance

  • Single Level Inheritance
  • Multilevel Inheritance


Single Level Inheritance:  

In Single Level Inheritance, the Parent class methods will be extended by the child class. All the methods can be inherited.

For implementing the single inheritance concept in PHP, we require two classes one as a parent and the other as a child. Let us have two such classes named A and B, respectively as shown below.

Example for Single Level Inheritance

<?php
	class A {
		public function getItem($string) {
			echo "Hello :" . $string;
		}
		public function getPHP() {
			echo "I am from valuebound" . PHP_EOL;
		}
	}
	class B extends A {
		public function getItem($string) {
			echo "Hi:" . $string . PHP_EOL;
		}
		public function getPHP() {
			echo "I am from ABC";
		}	
	}
	$a = new A();
	$b = new B();
	$a->getItem("Karan");
	$a->getPHP();
	$b->getItem("Shivani");
	$b->getPHP();
?>

Output:

Hello: Karan
I am from valuebound
Hello: Shivani
I am from ABC


Multi Level Inheritance:

In Multi level Inheritance, the parent class method will be inherited by child class and again subclass will inherit the child class method. 

<?php
	class A {
		public function getMyage() {
			return "age is 90";
		}
	}
	class B extends A {
		public function getMysonage() {
			return "age is 60";
		}
	}
	class C extends B {
		public function getMygrandsonage() {
			return "age is 30";
		}
		public function getmyHistory() {
			echo "Class A " .$this->getMyage();
			echo "Class B ".$this-> getMysonage();
			echo "Class C " . $this->getMygrandsonage();
		}
	}
	$obj = new C();
	$obj->getmyHistory();
?>

Output:

Class A is 90
Class B is 60 
Class C 30

 

Series: PHP Object Oriented Tutorials Hub
All Topics
Free Download Projects
Previous Chapter
Next Chapter

Ask a Question

Have a coding query or doubt? Ask here and get help from our community.

500 characters remaining
Submitting...
Free Download Projects
Join Telegram Group Join WhatsApp Group
Related Topics:
inheritance in php easyolearning types of inheritance in php multiple inheritance in php with example multilevel inheritance in php with example hierarchical inheritance in php with example hybrid inheritance in php inheritance in php pdf php inheritance constructor

Member Sign In

Forgot?
Signing in...

Don't have an account? Register here

Create Free Account

Register Captcha
Registering...

Already have an account? Sign In

Ask a Question

500 characters remaining
Submitting...

About Easy To Learning

Easy To Learning is a comprehensive programming learning portal offering free, practical, developer-driven tutorials for PHP, Java, Python, Spring, MySQL, CSS, Bootstrap, CakePHP, and more.

Explore community-contributed questions and answers, and download ready-to-run source code projects.

Quick Links

  • Home
  • Questions & Answers
  • Download Projects
  • Blog & Articles
  • Member Login

Community

  • Telegram Group
  • WhatsApp Community
  • Ask a Question
  • Join as Member

Connect With Us

Stay updated with our newest programming tutorials and free open source projects.

© 2026 Easy To Learning. All Rights Reserved.