note 75432 added to language.oop5.interfaces

From: Date: Wed, 30 May 2007 02:31:14 +0000
Subject: note 75432 added to language.oop5.interfaces
Groups: php.notes 
Request: Send a blank email to php-notes+get-127006@lists.php.net to get a copy of this message
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? ---- Server IP: 69.147.83.197 Probable Submitter: 74.128.25.156 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.interfaces.php Edit -- https://master.php.net/note/edit/75432 Del: integrated -- https://master.php.net/note/delete/75432/integrated Del: useless -- https://master.php.net/note/delete/75432/useless Del: bad code -- https://master.php.net/note/delete/75432/bad+code Del: spam -- https://master.php.net/note/delete/75432/spam Del: non-english -- https://master.php.net/note/delete/75432/non-english Del: in docs -- https://master.php.net/note/delete/75432/in+docs Del: other reasons-- https://master.php.net/note/delete/75432 Reject -- https://master.php.net/note/reject/75432 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#127006) next »