From:             chris42 dot b at googlemail dot com
Operating system: windows xp
PHP version:      5.2SVN-2009-10-26 (snap)
PHP Bug Type:     SPL related
Bug description:  ArrayIterator does not clone itself when referencing itself

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 bug report at http://bugs.php.net/?id=50000&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=50000&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=50000&r=trysnapshot53
Try a snapshot (PHP 6.0):            
http://bugs.php.net/fix.php?id=50000&r=trysnapshot60
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=50000&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=50000&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=50000&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=50000&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=50000&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=50000&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=50000&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=50000&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=50000&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=50000&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=50000&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=50000&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=50000&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=50000&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=50000&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=50000&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=50000&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=50000&r=mysqlcfg

Reply via email to