|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-11-09 05:45 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 29 21:00:01 2025 UTC |
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.