#42316 [Opn->Bgs]: ArrayIterator mix refcount and reference
| From: | jani@php.net | Date: | Fri, 17 Aug 2007 00:58:19 +0000 |
| Subject: | #42316 [Opn->Bgs]: ArrayIterator mix refcount and reference | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-116207@lists.php.net to get a copy of this message | ||
ID: 42316
Updated by: jani@php.net
Reported By: titerm at lfdj dot com
-Status: Open
+Status: Bogus
Bug Type: SPL related
Operating System: Windows
PHP Version: 5.2.3
New Comment:
But I'm using latest CVS. Perhaps you should have tried it too before
reporting already fixed bug.
Previous Comments:
------------------------------------------------------------------------
[2007-08-16 14:07:40] titerm at lfdj dot com
I did my test on 5.2.3 release on window and solaris.
I don't understand why you say original array is not modified since i'm
using offsetSet function, it should modified $arr and it does.
If i init $arr with $data1 and $data2 like this, only branch one is
altered.
$data1['one'] = 'ORG';
$data2['one'] = 'ORG';
$arr = array (
'branch1' => $data1,
'branch2' => $data2,
);
------------------------------------------------------------------------
[2007-08-16 13:47:51] jani@php.net
Since the iterator does not modify original array, this is the expected
result of your script (and what I get using latest CVS build):
array(2) {
["branch1"]=>
array(1) {
["one"]=>
string(3) "ORG"
}
["branch2"]=>
array(1) {
["one"]=>
string(3) "ORG"
}
}
------------------------------------------------------------------------
[2007-08-16 12:11:48] titerm at lfdj dot com
Create a ArrayIterator on branch1. Alter the leaf by using iterator.
Leave on branch2 are affected too.
Simplified reproduce code.
$data['one'] = 'ORG';
$arr = array (
'branch1' => $data,
'branch2' => $data,
);
$iterator = new ArrayIterator($arr['branch1']);;
$iterator->offSetSet($iterator->key(), 'ALTER' );
var_dump($arr);
Expected result
array
'branch1' =>
array
'one' => string 'ALTER' (length=5)
'branch2' =>
array
'one' => string 'ORG' (length=3)
Actual result
array
'branch1' =>
array
'one' => string 'ALTER' (length=5)
'branch2' =>
array
'one' => string 'ALTER' (length=5)
------------------------------------------------------------------------
[2007-08-16 10:45:42] jani@php.net
What if you didn't pay attention to the internals like refcount but
only for actual results? Can you come up with a short and simple example
of what actually doesn't work?
------------------------------------------------------------------------
[2007-08-16 08:32:05] titerm at lfdj dot com
I have simplified the reproduce code to much. Sorry
it should be
$iterator = new RecursiveIteratorIterator(new
RecursiveArrayIterator($arr['l1']));
foreach($iterator as $leaf) {
$iterator->offSetSet($iterator->key(), 'ALTER' );
}
Expected result
array(3) refcount(2){
["l1"]=>
array(1) refcount(1){
["one"]=>
array(1) refcount(1){
["two"]=>
string(5) "ALTER" refcount(1)
}
}
["l2"]=>
array(1) refcount(1){
["one"]=>
array(1) refcount(1){
["two"]=>
string(3) "ORG" refcount(2)
}
}
["l3"]=>
array(1) refcount(1){
["one"]=>
array(1) refcount(1){
["two"]=>
string(3) "ORG" refcount(1)
}
}
}
Actual Result
array(3) refcount(2){
["l1"]=>
array(1) refcount(3){
["one"]=>
array(1) refcount(1){
["two"]=>
string(5) "ALTER" refcount(1)
}
}
["l2"]=>
array(1) refcount(1){
["one"]=>
array(1) refcount(1){
["two"]=>
string(3) "ORG" refcount(2)
}
}
["l3"]=>
array(1) refcount(3){
["one"]=>
array(1) refcount(1){
["two"]=>
string(5) "ALTER" refcount(1)
}
}
}
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/42316
--
Edit this bug report at http://bugs.php.net/?id=42316&edit=1