note 75432 rejected from language.oop5.interfaces by tularis
| From: | tularis@php.net | Date: | Wed, 30 May 2007 12:14:32 +0000 |
| Subject: | note 75432 rejected from language.oop5.interfaces by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-127027@lists.php.net to get a copy of this message | ||
Note Submitter: quickshiftin at gmail dot com
----
PHP5 doesnt support interface inheritence.
Here is some sample code for discussion:
<?php
interface FirstInterface {
public function firstInterface();
}
interface SecondInterface {
public function secondInterface();
}
interface ThirdInterface extends FirstInterface {
public function firstInterface();
public function fourthInterface();
}
interface FourthInterface extends FirstInterface, SecondInterface {
public function firstInterface();
public function secondInterface();
public function fourthInterface();
}
abstract class FifthInterface implements FirstInterface, SecondInterface {
public function firstInterface() {}
public function secondInterface() {}
public abstract function fifthInterface();
?>
In Java one can inherit interfaces while defining interfaces
such as seen above in the definitions of ThirdInterface and FourthInterface.
This is logically sound because, all methods in the original interface
are garunteed to be abstract
and the new definition is simply saying it contains
the same public abstract methods.
In PHP 5 however, an Fatal error is raised when trying to parse the file:
Fatal error: Can't inherit abstract function FirstInterface::firstInterface()
(previously declared abstract in ThirdInterface) in
/usr/share/php5/experimentation/interfaces/
testInterfaceImplementsMultipleInterfaces.php on line 19
(a similar error is raised for fourthInterface).
There is a bloated workaround for this,
declaring an abstract class that implements said interfaces and
defines empty method bodies, see FifthInterface above.
I consider this a limitation.
Can someone rationalize this or is it a known limitation?