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:4
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 you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

Pull requests:

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-2024 The PHP Group
All rights reserved.
Last updated: Wed Dec 04 05:01:29 2024 UTC