onlinecode

Multilevel and Multiple Inheritance in PHP – onlinecode

Multilevel and Multiple Inheritance in PHP – onlinecode

In this post we will give you information about Multilevel and Multiple Inheritance in PHP – onlinecode. Hear we will give you detail about Multilevel and Multiple Inheritance in PHP – onlinecodeAnd how to use it also give you demo for it if it is necessary.

Multilevel and Multiple Inheritance in PHP :

PHP OOP does not allow multiple inheritance, it allow only multilevel inheritance.

In simple word, subclass can not extend more than one super class.
But PHP allow hierarchical inheritance, Hierarchical inheritance means child can get property of their parent and parent can get property of grand parent, so in this way child can get also some property of their grand parent.

Best example of multiple inheritance in PHP

  1. class demo
  2. {
  3. //Your class body
  4. }
  5. class demo1
  6. {
  7. //Your class body
  8. }
  9. class demo3 extends demo1 demo2
  10. {
  11. //your class body
  12. }
class demo{//Your class body}class demo1{//Your class body}class demo3 extends demo1 demo2{//your class body}

Above code will not work in php because php does not allow multiple inheritance.

Best example of multilevel inheritance in PHP

  1. class grandParent
  2. {
  3. //Body of grand parent class
  4. }
  5. class parent extends grandParent
  6. {
  7. //Body Of parent class
  8. }
  9. class child extends parent
  10. {
  11. //Body of child class
  12. }
class grandParent{//Body of grand parent class}class parent extends grandParent{//Body Of parent class}class child extends parent{//Body of child class}
See also  Laravel - Dynamically Add or Remove input fields using JQuery

Above example is so clear to understand, child class is extending parent class and parent class is extending grand parent.This was a very basic example to understand the concept of multilevel inheritance in php oops.

Note : only Interfaces support multiple inheritance

Label :

PHP

OOP

Object Oriented Programming

Hope this code and post will helped you for implement Multilevel and Multiple Inheritance in PHP – onlinecode. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Exit mobile version