|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-05-18 15:43 UTC] mike@php.net
-Status: Assigned
+Status: Feedback
[2010-05-18 15:43 UTC] mike@php.net
[2013-02-18 00:34 UTC] php-bugs at lists dot php dot net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 20 21:00:02 2025 UTC |
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" }