php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35163 Array elements can lose references.
Submitted: 2005-11-09 05:45 UTC Modified: 2007-11-01 09:28 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: averagomez at hotmail dot com Assigned: dmitry (profile)
Status: Closed Package: Arrays related
PHP Version: 5CVS-2005-11-09 (cvs) OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: averagomez at hotmail dot com
New email:
PHP Version: OS:

 

 [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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-11-16 14:52 UTC] 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.

 [2006-08-01 23:03 UTC] tony2001@php.net
Not reproducible with 5.2-CVS.
 [2006-09-01 04:39 UTC] dmitry@php.net
The bug still exists in 5.2 it need just another test script.
 [2007-10-23 09:56 UTC] dmitry@php.net
Fixed in CVS HEAD and PHP_5_3 (not in PHP_5_2).
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Jul 04 20:01:35 2025 UTC