|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60161 Implementing an interface extending Traversable is order dependent
Submitted: 2011-10-28 18:45 UTC Modified: 2020-02-26 15:49 UTC
Avg. Score:4.8 ± 0.4
Reproduced:5 of 5 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: Assigned: nikic (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.4.0beta2 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
New email:
PHP Version: OS:


 [2011-10-28 18:45 UTC]
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.


Responsible code:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-11-02 12:21 UTC]
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-11-02 14:44 UTC]
@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 17:16 UTC]
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 17:50 UTC]
Yes, exactly. That's what I was trying to do when I encountered the issue.
 [2013-10-12 17:57 UTC] maciej dot sz at gmail dot com
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:

interface IFoo extends \Traversable

abstract class AFoo implements IFoo

Class AFoo must implement interface Traversable as part of either Iterator or IteratorAggregate in Unknown on line 0
 [2014-03-27 01:31 UTC]
I don't care as much about the abstract issue (it's filed separately: but I'd really like to see the order restriction be relaxed on interfaces.
 [2016-12-13 00:28 UTC] thecelavi at mac dot com

Expected: Every example should execute fine.
 [2020-02-26 15:49 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2020-02-26 15:49 UTC]
Looks like this got fixed in 7.4. Test added in
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jul 18 10:01:29 2024 UTC