Jump to content

class - inheritance..


jaikar

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/93575-class-inheritance/#findComment-479514
Share on other sites

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) {

    }
}

?>

Link to comment
https://forums.phpfreaks.com/topic/93575-class-inheritance/#findComment-479520
Share on other sites

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 !....

Link to comment
https://forums.phpfreaks.com/topic/93575-class-inheritance/#findComment-479699
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.