Program For Multiple Inheritance - Php

How to use multiple inheritance concept in php?

Snippet Code


  
Rate this page :
  [ 0 votes]

To implement multiple inheritance in php you can use "Traits". Trait is similar to an abstract class which cannot be instained on its own and it is intented to reduce some limitations of single inhereitance and it enables developer to reuse set of several independent classes living in various class hierarchies. The mainclass shows how to use "trait". The code for multiple inheritance in php is given below.

<?php class baseclass { public function Hello() { echo 'Hiox '; } } trait extendedclass { public function Hello() { parent::Hello(); echo 'Softwares!!'; } } class mainclass extends baseclass { use extendedclass; } $obj = new mainclass(); $obj->Hello(); ?>

Tags


Ask Questions

Ask Question