#42316 [NEW]: RecursiveArrayIterator mix refcount and reference

From: Date: Thu, 16 Aug 2007 08:18:32 +0000
Subject: #42316 [NEW]: RecursiveArrayIterator mix refcount and reference
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-116155@lists.php.net to get a copy of this message
From:             titerm at lfdj dot com
Operating system: Windows
PHP version:      5.2.3
PHP Bug Type:     SPL related
Bug description:  RecursiveArrayIterator mix refcount and reference

Description:
------------
When multiple entries of an array are initialized with a $base var array,
new entries will increase refcount.
Any modification of this new entries should decrease refcount.

But if modification are done through a recursive Array Iterator, refcount
works like it was reference, and all leaf are modified

Reproduce code:
---------------
// Reference var array
$base['one']['two'] = 'ORG';

// Work array
$arr = array (
	'l1' => $base,
	'l2' => $base,
	'l3' => $base,
);
unset($base); // No need anymore of reference 

// Break refcount for level 2, level 1 and level 3 are still refcount
$arr['l2']['one']['two'] =
$arr['l2']['one']['two'];

// Create an iterator on level 1
$iterator = new RecursiveIteratorIterator(new
RecursiveArrayIterator($arr['l1']));
// Alter leaf of level 1
$iterator->offSetSet($iterator->key(), 'ALTER' );
debug_zval_dump($arr);


Expected result:
----------------
array(3) refcount(2){
  ["l1"]=>
  array(1) refcount(1){
    ["one"]=>
    string(5) "ALTER" refcount(1)
  }
  ["l2"]=>
  array(1) refcount(1){
    ["one"]=>
    array(1) refcount(1){
      ["two"]=>
      string(3) "ORG" refcount(1)
    }
  }
  ["l3"]=>
  array(1) refcount(1){
    ["one"]=>
    string(3) "ORG" refcount(1)
  }
}

Actual result:
--------------
array(3) refcount(2){
  ["l1"]=>
  array(1) refcount(3){
    ["one"]=>
    string(5) "ALTER" refcount(1)
  }
  ["l2"]=>
  array(1) refcount(1){
    ["one"]=>
    array(1) refcount(1){
      ["two"]=>
      string(3) "ORG" refcount(1)
    }
  }
  ["l3"]=>
  array(1) refcount(3){
    ["one"]=>
    string(5) "ALTER" refcount(1)
  }
}

-- 
Edit bug report at http://bugs.php.net/?id=42316&edit=1
-- 
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=42316&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=42316&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=42316&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=42316&r=fixedcvs
Fixed in release:             http://bugs.php.net/fix.php?id=42316&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=42316&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=42316&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=42316&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=42316&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=42316&r=notwrong
Not enough info:              http://bugs.php.net/fix.php?id=42316&r=notenoughinfo
Submitted twice:              http://bugs.php.net/fix.php?id=42316&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=42316&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=42316&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=42316&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=42316&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=42316&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=42316&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=42316&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=42316&r=mysqlcfg


Thread (9 messages)

« previous php.bugs (#116155) next »