#35163 [Asn->Csd]: Array elements can lose references.
| From: | dmitry@php.net | Date: | Thu, 01 Nov 2007 09:28:34 +0000 |
| Subject: | #35163 [Asn->Csd]: Array elements can lose references. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-119183@lists.php.net to get a copy of this message | ||
ID: 35163
Updated by: dmitry@php.net
Reported By: averagomez at hotmail dot com
-Status: Assigned
+Status: Closed
Bug Type: Arrays related
Operating System: *
PHP Version: 5CVS-2005-11-09 (cvs)
Assigned To: dmitry
Previous Comments:
------------------------------------------------------------------------
[2007-10-23 09:56:26] dmitry@php.net
Fixed in CVS HEAD and PHP_5_3 (not in PHP_5_2).
------------------------------------------------------------------------
[2006-09-01 04:39:08] dmitry@php.net
The bug still exists in 5.2 it need just another test script.
------------------------------------------------------------------------
[2006-08-01 23:03:00] tony2001@php.net
Not reproducible with 5.2-CVS.
------------------------------------------------------------------------
[2005-11-16 14:52:19] dmitry@php.net
5.1 is effected too.
<?php
$a = array(array('A'));
//$b = &$a[0];
$a[0][] =& $a[0];
$a[0][] =& $a[0];
$a[0][0] = 'b';
var_dump($a);
$a = null;
$b = null;
?>
The problem is in "$a[0][] =& $a[0];" operator, that creates copy of
$a[0] during fetching lvalue because $a[0] is not a reference and after
fetching rvalue it has refcount > 1.
------------------------------------------------------------------------
[2005-11-09 05:45:44] averagomez at hotmail dot com
Description:
------------
Sorry I have a very bad english but I think the 'Reproduce code' is
self-describing.
Reproduce code:
---------------
// ---------- This work OK:
$a = array('A', & $a, & $a);
$a[1][0] = 'B';
echo $a[0]; // OK : Show 'B'
// ---------- But this don't work:
$a = array('A');
$a[1] = & $a;
$a[2] = & $a;
$a[1][0] = 'B';
echo $a[0]; // Wrong: Show 'A'
Expected result:
----------------
BB
Actual result:
--------------
BA
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=35163&edit=1