|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50000 ArrayIterator does not clone itself when referencing itself
Submitted: 2009-10-26 13:46 UTC Modified: 2013-02-18 00:34 UTC
Avg. Score:4.4 ± 0.5
Reproduced:5 of 5 (100.0%)
Same Version:3 (60.0%)
Same OS:3 (60.0%)
From: chris42 dot b at googlemail dot com Assigned: colder (profile)
Status: No Feedback Package: SPL related
PHP Version: 5.2SVN-2009-10-26 (snap) OS: windows xp
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:
From: chris42 dot b at googlemail dot com
New email:
PHP Version: OS:


 [2009-10-26 13:46 UTC] chris42 dot b at googlemail dot com
In test file array_022.phpt we see the clone being changed but this does not change original, If you clone an ArrayIterator you also clone its reference.

If you take such a self-wrapping ArrayIterator and clone it, the clone is no longer self-wrapping: the clone wraps the original. HOWEVER, I *think* the SPL_ARRAY_IS_SELF flag is being copied to the clone 

Therefore, the clone starts to store/retrieve data from itself rather than from its wrapped container - hence the difference. 

Reproduce code:

class MyArrayIterator extends ArrayIterator
	public function __construct()
		$this['bar'] = 'baz';

$a = new MyArrayIterator;

$b = clone $a;
$b['baz'] = 'Foo';



Expected result:
object(MyArrayIterator)#%d (2) {
  string(3) "baz"
  string(3) "Foo"
object(MyArrayIterator)#%d (2) {
  string(3) "baz"
  string(3) "Foo"

Actual result:
object(MyArrayIterator)#%d (1) {
  string(3) "baz"
object(MyArrayIterator)#%d (2) {
  string(3) "baz"
  string(3) "Foo"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-05-18 15:43 UTC]
-Status: Assigned +Status: Feedback
 [2010-05-18 15:43 UTC]
So, you say, that the test-case is wrong in the first place?
 [2013-02-18 00:34 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Thu Aug 18 01:05:45 2022 UTC