jaikar Posted February 28, 2008 Share Posted February 28, 2008 hi there.. is it possible to write a class such a way that it can extend from 2 or more classes. as far i know a class can extend only from one class. is that true? thanks in advance ~J Quote Link to comment Share on other sites More sharing options...
premiso Posted February 28, 2008 Share Posted February 28, 2008 I am not sure about PHP 5 but I know in PHP 4 multiple inheritance is not possible, there have been workarounds I believe on the PHP.Net site under inheritance that used to work, but in short there is no "correct" way to do multiple inheritance in PHP 4 at least, again I am not sure about PHP 5. Quote Link to comment Share on other sites More sharing options...
keeB Posted February 28, 2008 Share Posted February 28, 2008 PHP 5, like Java, offers multiple interfaces rather than multiple inheritance. <?php interface foo { function mustbeoverriden($a, $b); } interface bar { function someotherfunction($c, $d); } class MyClass implements foo, bar { public function mustbeoverriden($a, $b) { } public function someotherfunction($c, $d) { } } ?> Quote Link to comment Share on other sites More sharing options...
keeB Posted February 28, 2008 Share Posted February 28, 2008 From http://us2.php.net/manual/en/keyword.extends.php An extended class is always dependent on a single base class, that is, multiple inheritance is not supported. Quote Link to comment Share on other sites More sharing options...
jaikar Posted February 29, 2008 Author Share Posted February 29, 2008 hi everyone.. thanks for your replies!, i learned a new thing today ... thanks !.. actualy i have scenario to use 2 class in another class, one class i extended, and then i was not sure how to extend with the 2nd one... but i just instanciated the 2nd class object, i think the only disadvantage is except that method, other methods cannot use the object... how it will be when the second class extends first class then third class extends second class and so on and so fourth... is it possible for the last class to use the first class's method directly using $this ? Thanks !.... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.