![How can I extend 2 classes in PHP? [duplicate]](https://www.xszz.org/skin/wt/rpic/t9.jpg)
Question:
<blockquote>
<strong>Possible Duplicate:</strong><br /><a href="https://stackoverflow.com/questions/90982/multiple-inheritance-in-php" rel="nofollow">Multiple Inheritance in PHP</a><br /><a href="https://stackoverflow.com/questions/356128/can-i-extend-a-class-using-more-than-1-class-in-php" rel="nofollow">Can I extend a class using more than 1 class in PHP?</a>
</blockquote>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?
Answer1:PHP, like Java, does not support multiple inheritance.
Coming in PHP 5.4 will be <a href="https://secure.php.net/manual/en/language.oop5.traits.php" rel="nofollow">traits</a> 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.
Answer2:PHP doesn't really support multiple inheritance, but there are some (somewhat messy) ways to implement it. Check out this URL for some examples:
<a href="http://www.jasny.net/articles/how-i-php-multiple-inheritance/" rel="nofollow">http://www.jasny.net/articles/how-i-php-multiple-inheritance/</a>
Answer3: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:
<a href="https://stackoverflow.com/questions/90982/multiple-inheritance-in-php" rel="nofollow">Multiple Inheritance in PHP</a>