Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Is it possible to extend and implement a class in PHP (or other languages)?

More of a question to satisfy my own curiosity...

If i have an interface

interface foo {

.

.

.

}

and a class

class bar {

.

.

.

}

can I create an new class that extend and implements the above?

class fooBar extends bar implements foo {}

I tried the above but it failed, so maybe the syntax is wrong or it is just not possible.

3 Answers

Relevance
  • 1 decade ago
    Favorite Answer

    Please be sure to implement all the interface methods. I have tried the following PHP code and it works fine:

    <?php

    interface foo { }

    class bar { }

    class fooBar extends bar implements foo { }

    ?>

    To read more about interfaces in PHP, see

    http://th.php.net/manual/en/language.oop5.interfac...

  • 1 decade ago

    I do not know about PHP but yes, you can do that in other programming languages such as Java.

    class Cat extends Animal implements Pets {

    }

  • Anonymous
    4 years ago

    No 'classes' (merchandise orientated Programming OOP i think of is the term your finding for) isn't new in own living house page, although the extends works very corresponding to a commonplace contain or require assertion does in own living house page yet its extra modular interior the incontrovertible fact which you're no longer having to reference little ones classes interior the parent. different ameliorations being encapsulation and products could be converted into virtually any data style making suggestions lots extra versatile. evaluate the class your blueprint the object is what it creates at runtime, and the procedures are the needs that could be utilized on that particular merchandise. classes and techniques could be deemed public, inner maximum or secure. Public... being obtainable to all people, even different web content, inner maximum... are purely usable interior of that merchandise occasion that they are created for that's it incredibly is a 'black container', and guarded... purely obtainable to that merchandise occasion and to little ones of the class/baby products.

Still have questions? Get your answers by asking now.