Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>First; I am understanding Inheritance in OOP, but what I am not understanding in PHP is why I can only use extends once to extend a parent class. I have been doing some reading online and a few times I have seen where it is not good practice to use extends more than once, that's why it's not available, is this true?</p> </blockquote> <p>In short: Its just a design decission from the PHP core developers. Multiple inheritance brings up many questions, for example what should happen, when two parent classes implements the same method? To avoid such conflicts some languages decide to not support it (e.g. Java too ;)). There is no real downside in it.</p> <blockquote> <p>Second; Abstract vs. Interface, I read a way to Inherit one class many times is to use Interface and or Abstract. Is this correct?</p> </blockquote> <p>You can extend every class as much as you like. There is no limitation neither for classes, abstract classes, nor interfaces. However, its possible to implement (<code>implements</code> keyword) more than one interface into one class.</p> <blockquote> <p>Third; I am writing a very simple class using Inheritance and I am having a problem understanding how to properly contruct it. I have looked thru php.net and OS and have seen many classes and how they are written, but could anyone take the time to write a simple example in PHP using .... let's say a mammal class as the parent class and have dog, cat, and bear and the child classes.</p> </blockquote> <pre><code>abstract class Mammal {} class Dog extends Mammal {} class Cat extends Mammal {} class Bear extends Mammal {} </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload