2

I have 3 classes (3 files):

a.class.php
b.class.php
c.class.php

I want to extend class a and b in the class c (file 3):

How I could do that? I want to use both class functions of a + b in my new class C

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Cheerio
  • 1,260
  • 6
  • 19
  • 37
  • See my answer [to another question](http://stackoverflow.com/questions/1314875/is-a-general-class-necessary-for-a-site-php-site/1314996#1314996) – JW. Feb 20 '11 at 20:22
  • you can use function __call() http://stackoverflow.com/questions/356128/can-i-extend-a-class-using-more-than-1-class-in-php – jhenya-d Nov 01 '16 at 12:35
  • try function __call() answer here http://stackoverflow.com/questions/356128/can-i-extend-a-class-using-more-than-1-class-in-php – jhenya-d Nov 01 '16 at 12:36

5 Answers5

8

You are asking for multiple inheritance, which is not supported by php. You should have a look at composition instead.

Philipp
  • 1,903
  • 2
  • 24
  • 33
4

There is no multiple inheritance in PHP. So you can't do that.

Try using composition and re-arranging your class structure.

Pablo Santa Cruz
  • 176,835
  • 32
  • 241
  • 292
1

There is a way of achieving this in PHP using mixins. See this http://www.phpdeveloper.org/news/6139 for example. However I would probably try to find a different way of designing your code so you don't have to use it.

Otherwise PHP 5.4 will bring Traits which will natively support what you want: http://simas.posterous.com/new-to-php-54-traits

poisson
  • 1,324
  • 11
  • 20
-4

Class c extends a implements interface

Done

-4

class a

class b extends a

class c extends b

done.