Bug #50000 [Asn->Fbk]: ArrayIterator does not clone itself when referencing itself
| From: | mike@php.net | Date: | Tue, 18 May 2010 13:43:11 +0000 |
| Subject: | Bug #50000 [Asn->Fbk]: ArrayIterator does not clone itself when referencing itself | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-150562@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=50000&edit=1
ID: 50000
Updated by: mike@php.net
Reported by: chris42 dot b at googlemail dot com
Summary: ArrayIterator does not clone itself when referencing
itself
-Status: Assigned
+Status: Feedback
Type: Bug
Package: SPL related
Operating System: windows xp
PHP Version: 5.2SVN-2009-10-26 (snap)
Assigned To: colder
New Comment:
So, you say, that the test-case is wrong in the first place?
Previous Comments:
------------------------------------------------------------------------
[2009-10-26 13:46:47] chris42 dot b at googlemail dot com
Description:
------------
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:
---------------
<?php
class MyArrayIterator extends ArrayIterator
{
public function __construct()
{
parent::__construct($this);
$this['bar'] = 'baz';
}
}
$a = new MyArrayIterator;
$b = clone $a;
$b['baz'] = 'Foo';
var_dump($a);
var_dump($b);
?>
Expected result:
----------------
object(MyArrayIterator)#%d (2) {
["bar"]=>
string(3) "baz"
["baz"]=>
string(3) "Foo"
}
object(MyArrayIterator)#%d (2) {
["bar"]=>
string(3) "baz"
["baz"]=>
string(3) "Foo"
}
Actual result:
--------------
object(MyArrayIterator)#%d (1) {
["bar"]=>
string(3) "baz"
}
object(MyArrayIterator)#%d (2) {
["bar"]=>
string(3) "baz"
["baz"]=>
string(3) "Foo"
}
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=50000&edit=1