2

In PHP, is it possible to have multiple inheritance (by the nature of the PHP, not writting modification code)?

For example :

class a
{
    public function foo();
}

class b
{
    public function bar();
}

class c extends a, b
{
    public function baz();
}
thkala
  • 80,583
  • 22
  • 150
  • 196
redcoder
  • 2,153
  • 2
  • 14
  • 5

2 Answers2

1

No. There's no real multiple inheritance in PHP and thats a good thing. See the other answers for alternatives.

Edit: By now, PHP supports Traits, of which one class can include more than one. They avoid the usual problems of multiple inheritance by throwing an error or requiring you to alias conflicting names.

selfawaresoup
  • 14,913
  • 7
  • 34
  • 47
0
class A extends B{

}

class B extends C{

}

class C{

}
Mahbub Alam
  • 338
  • 2
  • 5