|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #67189 Clone is not implemented for IteratorIterator and related classes
Submitted: 2014-05-03 12:16 UTC Modified: 2018-08-19 15:59 UTC
Avg. Score:4.0 ± 0.7
Reproduced:4 of 4 (100.0%)
Same Version:1 (25.0%)
Same OS:0 (0.0%)
From: ottodavid at gmx dot net Assigned:
Status: Open Package: SPL related
PHP Version: 5.5.12 OS: OS X
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: ottodavid at gmx dot net
New email:
PHP Version: OS:


 [2014-05-03 12:16 UTC] ottodavid at gmx dot net
IteratorIterator and derived classes like FilterIterator, RegexIterator etc. are not cloneable, because the implementation for spl_dual_it.clone_obj is missing.

This is issue, especially because Iterator is clonable, IteratorIterator is derived from Iterator and is not clonable, thereby violating the liskov substitution principle.

Test script:

$arrayIterator = new ArrayIterator(array(1,2,3));
$it1 = new IteratorIterator($arrayIterator);
$it2 = clone $it1;

Actual result:
PHP Fatal error:  Trying to clone an uncloneable object of class IteratorIterator 


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-05-06 08:41 UTC]
Iterator is an interface which doesn't make any requirements towards cloneability. Adding clone support for IteratorIterator isn't easy as we can't guarantee state always.
 [2014-11-28 15:15 UTC]
@Johannes: There is a PR pending for this one, which looks right to me. Can you read it / elaborate about your previous comment ?
 [2015-02-17 23:11 UTC] ottodavid at gmx dot net
Sorry I missed to see that Iterator is just an interface.

Anyway, my PR implements/improves/fixes this functionality, Is there any chance to get it merged?
 [2018-08-19 15:59 UTC]
-Type: Bug +Type: Feature/Change Request
 [2018-08-19 15:59 UTC]
Since IteratorIterator is a base class, it does not violate the
LSP, so I'm changing to feature request.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 14 19:01:28 2024 UTC