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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.