Bug->Doc #62464 [Opn->Csd]: implementing two interfaces with same signature no longer gives a fatal error

From: Date: Mon, 27 Jan 2020 14:12:36 +0000
Subject: Bug->Doc #62464 [Opn->Csd]: implementing two interfaces with same signature no longer gives a fatal error
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-17225@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=62464&edit=1 ID: 62464 Updated by: cmb@php.net Reported by: j dot henge-ernst at interexa dot de Summary: implementing two interfaces with same signature no longer gives a fatal error -Status: Open +Status: Closed -Type: Bug +Type: Documentation Problem Package: Scripting Engine problem Operating System: linux PHP Version: 5.3Git-2012-07-02 (Git) -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: Since the behavior is properly documented, and any change would require at least discussion on the internals@ mailing list[1] (and may an RFC), I'm closing this as documentation issue. [1] <https://www.php.net/mailing-lists.php> Previous Comments: ------------------------------------------------------------------------ [2016-09-22 17:22:24] phansys at gmail dot com The documentation states that for PHP >= 5.3.9, this is the expected behavior: http://php.net/manual/en/language.oop5.interfaces.php ------------------------------------------------------------------------ [2015-08-09 13:53:55] php at mcq8 dot be The documentation is updated. The concern stated in this bugreport is solved in php7 with return type declarations. An error will be triggered if you implement two interfaces that have the same method name but have a different return type. For example: interface AInterface { /** @return Aclass[] */ public function getObjects(): AClass; } interface BInterface { /** @return Bclass[] */ public function getObjects(): BClass; } class CClass implements AInterface, BInterface { public function getObjects(): AClass { return "???"; } } class AClass { public function foo() { echo "foo";} } class BClass { public function bar() { echo "bar";} } ------------------------------------------------------------------------ [2013-03-22 15:27:10] pawel dot ulewicz at gmail dot com Any news about it? I think the current behavior is ok(implementing two interfaces with same signatures should be possible), but it should be documented. Right now the documentation states clearly: "A class cannot implement two interfaces that share function names, since it would cause ambiguity.", so it looks like an undocumented feature(bug?) with uncertain status. I would use this in my code(and i'm not the only one, check the comments here: bug #33698), but i don't know if it's going to be removed in future versions or not. ------------------------------------------------------------------------ [2012-08-07 22:41:44] valderrama dot christopher at gmail dot com The certification guide states that a object can't implement two interfaces that share the same method, but the code still runs ok. So if classes are going to be allowed two implement two interfaces that share the same method, I think that the certification exam should be changed to reflect this change. ------------------------------------------------------------------------ [2012-07-02 22:11:54] j dot henge-ernst at interexa dot de Your example is ok and should work correctly as both interfaces extend the same base interface and add different methods. In my given example AInterface and BInterface do not extend from a common interface. So the class which implements RewindableIterator, ReversableIterator must implement from Iterator: function current(); function key(); function next(); function valid(); from RewindableIterator: function rewind(); from ReversableIterator: function prev(); So lets change my example to: interface AInterface { /** @return Aclass[] */ public function getObjects(); } interface BInterface { /** @return Bclass[] */ public function getObjects(); } class CClass implements AInterface, BInterface { public function getObjects() { return ???; } } class AClass { public function foo() { echo "foo";} } class BClass { public function bar() { echo "bar";} } ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=62464 -- Edit this bug report at https://bugs.php.net/bug.php?id=62464&edit=1

« previous php.doc.bugs (#17225) next »