php.net |  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
Votes:3
Avg. Score:3.7 ± 0.5
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
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
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ottodavid at gmx dot net
New email:
PHP Version: OS:

 

 [2014-05-03 12:16 UTC] ottodavid at gmx dot net
Description:
------------
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:
---------------
<?php

$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 

Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-05-06 08:41 UTC] johannes@php.net
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] jpauli@php.net
@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] cmb@php.net
-Type: Bug +Type: Feature/Change Request
 [2018-08-19 15:59 UTC] cmb@php.net
Since IteratorIterator is a base class, it does not violate the
LSP, so I'm changing to feature request.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Dec 11 16:01:26 2019 UTC