PHP - Extend multiple classes

10,448

Php doesnot allow multiple inhritance. There are two ways to do this -

First

class a { }

class b extends a { }

class c extends b { }

Interfaces -

interface sb { }

class c extends a implements sb { }
Share:
10,448
xpedobearx
Author by

xpedobearx

Updated on June 04, 2022

Comments

  • xpedobearx
    xpedobearx almost 2 years

    With "implements" I can force a class to define certain functions, but I need to add some functions to the interface to avoid duplicate code. This is only possible if I make the class "abstract" and use "extends". But "extends" only accepts one class. Because each of these classes are different, sort of like features of an app, I can't just extend one with the other. So is there any way to have

    class My extends Feature1, Feature2, Feature3{
    }
    

    ??