1

Possible Duplicate:
Multiple Inheritance in PHP
Can I extend a class using more than 1 class in PHP?

Does anyone know how can I extend 2 classes from one class?

Example: How can I add another class called classB into the following class?

<?php
class Test extends classA
{
   echo "test";
} 
?>

I tried the following code, but this is not work:

<?php
class Test extends classA, classB
{
   echo "test";
} 
?>

Anyone know how can I solve this issue?

Community
  • 1
  • 1
Jin Yong
  • 42,698
  • 72
  • 141
  • 187

3 Answers3

3

PHP, like Java, does not support multiple inheritance.

Coming in PHP 5.4 will be traits which attempt to provide a solution to this problem.

In the meantime, you would be best to re-think your class design. You can implement multiple interfaces if you're after an extended API to your classes.

Michael Mol
  • 508
  • 1
  • 3
  • 17
Phil
  • 157,677
  • 23
  • 242
  • 245
1

PHP doesn't really support multiple inheritance, but there are some (somewhat messy) ways to implement it. Check out this URL for some examples:

http://www.jasny.net/articles/how-i-php-multiple-inheritance/

Chris
  • 1,569
  • 2
  • 11
  • 18
0

What you're asking about is called "Multiple Inheritance". PHP doesn't support this, however you'd do well to have a read through this StackOverflow thread:

Multiple Inheritance in PHP

Community
  • 1
  • 1
KingJackaL
  • 780
  • 4
  • 17