Bug #60161 [Com]: Implementing an interface extending Traversable is order dependent

From: Date: Sat, 12 Oct 2013 17:57:02 +0000
Subject: Bug #60161 [Com]: Implementing an interface extending Traversable is order dependent
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-182133@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=60161&edit=1 ID: 60161 Comment by: maciej dot sz at gmail dot com Reported by: nikic@php.net Summary: Implementing an interface extending Traversable is order dependent Status: Open Type: Bug Package: Scripting Engine problem PHP Version: 5.4.0beta2 Block user comment: N Private report: N New Comment: The order dependency of interface names is a minor drawback, but same thing happens when one tries to put an abstract class between the interface and specific implementation. And this is a big problem: <?php interface IFoo extends \Traversable {} abstract class AFoo implements IFoo {} ?> Throws: Class AFoo must implement interface Traversable as part of either Iterator or IteratorAggregate in Unknown on line 0 Previous Comments: ------------------------------------------------------------------------ [2011-11-02 17:50:13] nikic@php.net Yes, exactly. That's what I was trying to do when I encountered the issue. ------------------------------------------------------------------------ [2011-11-02 17:16:29] johannes@php.net You mean for a type hint which says "traversable and having that function"? That might indeed be a valid reason I didn't think about .. ------------------------------------------------------------------------ [2011-11-02 14:44:55] nikic@php.net @johannes: How could you then hint that a class must be Traversable in some way (either Iterator or Aggregate)? Or shouldn't that be possible at all? ------------------------------------------------------------------------ [2011-11-02 12:21:47] johannes@php.net Actually we should forbid extending Traversable. This should only only only be used by internal classes (Iterator, iteratorAggregate or classes providing the C get_iterator hooks) ------------------------------------------------------------------------ [2011-10-28 18:45:18] nikic@php.net Description: ------------ When implementing an interface which extends Traversable together with one of the concrete Traversable implementations (i.e. Iterator or IteratorAggregate) the latter must be named first in order to not throw an error. Compare: http://codepad.viper-7.com/OJt8XN http://codepad.viper-7.com/1AnU5Z Responsible code: http://lxr.php.net/xref/PHP_5_4/Zend/zend_interfaces.c#zend_implement_traversable ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=60161&edit=1

« previous php.bugs (#182133) next »