Edit report at http://bugs.php.net/bug.php?id=46705&edit=1

 ID:                 46705
 Comment by:         clicky at erebot dot net
 Reported by:        wrzasq at gmail dot com
 Summary:            Impossible to implement compatible interfaces
 Status:             Open
 Type:               Feature/Change Request
 Package:            Feature/Change Request
 Operating System:   Debian GNU/Linux
 PHP Version:        5.2.6
 Block user comment: N
 Private report:     N

 New Comment:

I think this use case, the one bug #43200 and the one below are all
valid:



<?php

interface A

{

public function foo();

}



interface B

extends A

{

public function foo();

}



class C implements B

{

public function foo(){}

}



?>



The case above may seem odd (there's really no point in redefining the
exact same interface), but I have a simple use case where this may prove
handy.



I'm currently writing some code for a little project which is meant to
teach some middle to advanced topics of PHP. The code is self-documented
(using doxygen) and uses some interface from SPL (Countable). That
interface is used several times in different files and I'd like to
document the count() method only once (if possible, at the interface
level -- then using doxygen's ability to copy/paste the doc from parent
classes/interfaces into the current class).



I thought I could just define my own interface (Project_Countable),
extending from SPL's Countable, "overriding" the method's signature
(only so doxygen can pick up the method's declaration -- the prototype
for the method was actually left unchanged) and then define a class that
implements Project_Countable.

So in my case, A = SPL's Countable interface and B = Project_Countable.



However, this pattern can't be used as it results in the same error
others noted here and in bug #43200.

I can't simply avoid Project_Countable extending from Countable, because
then I would lose count()'s "magic" by doing so.


Previous Comments:
------------------------------------------------------------------------
[2008-11-28 07:57:42] wrzasq at gmail dot com

Description:
------------
It is impossible to implement multiple interfaces that declares same 

methods. I saw bug #43200 but this is a bit different case and I 

think in this situation it shoud be allowed - those interfaces 

requires methods with same signature (also to prevent further 

problems - optional parameters should also be allowed to match 

signatures):

Reproduce code:
---------------
<?php

interface A

{

public function foo();

}



interface B

{

public function foo();

}



class C implements A, B

{

public function foo(){}

}



Expected result:
----------------
nothing, but working

Actual result:
--------------
Fatal error: Can't inherit abstract function B::foo() (previously 

declared abstract in A) in /home/wrzasq/Desktop/Www/engine/- on line 

16


------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=46705&edit=1

Reply via email to