note 98855 deleted from language.oop5.inheritance by danbrown
| From: | danbrown@php.net | Date: | Mon, 12 Jul 2010 13:22:57 +0000 |
| Subject: | note 98855 deleted from language.oop5.inheritance by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-170876@lists.php.net to get a copy of this message | ||
Note Submitter: Anonymous
----
@jackdracona at msn dot com
With the exception of interfaces. Interfaces can extend multiple interfaces, but only other
interfaces.
On another note, it's a tad more complicated when chaining. There is a quirk which one may -
though probably rarely - encounter when using something like SPL
(http://www.php.net/manual/en/book.spl.php) as class extending may overlap in places.
* The extends keyword in the -current- class behaves like the "require" function. Going
in order from Left to Right in the extends list of your current class, no parent can be added to the
list if it was already extended by proxy in a previous parent in the list.
* The extends keyword in -parent- classes behaves like the "require_once" function. Going
in order from Left to Right in the extends list of your current class, if a parent itself extends an
interface already referenced prior in the list, it's ok.
Therefore, when extended parents which already extend each other, order and priority counts. I
doubt I'm making sense. Hopefully a mod can clean my note up to be more concise. But
here's the code to demonstrate this...
<?php
interface A {
public function testA();
}
interface B extends A {
public function testB();
}
interface C extends A,B {
public function testC();
}
?>
Had C extended in the order B,A it would cause a fatal "cannot implement previously implemented
interface A" error.
This same behavior is found when "implementing", where if I were to create a normal class
which implemented the above out of order A,B,C it would cause a fatal error.