php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27381 unset affects "copies" of an array
Submitted: 2004-02-24 13:25 UTC Modified: 2004-03-08 07:11 UTC
Votes:2
Avg. Score:3.0 ± 2.0
Reproduced:1 of 2 (50.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: abk at avatartechnology dot com Assigned:
Status: Closed Package: Arrays related
PHP Version: 4.3.4 OS: Win 2K pro
Private report: No CVE-ID:
 [2004-02-24 13:25 UTC] abk at avatartechnology dot com
Description:
------------
Unsetting an element of an array unsets that element in copies of the array. This does not happen if you change the array or its copy in some other way after making the copy and before doing the unset. I haven't tested whether this affects other non-atomic types like objects, but it wouldn't surprise me if it does.

My educated guess is there is some copy-on-write optomization that (wrongly) does not consider "unset" to be a write.

Reproduce code:
---------------
$x = array(1,2);
$y = $x;
# uncommenting the next line "fixes" the bug:
#$x[0] = $x[0];
unset($x[0]);
print_r($y);

Expected result:
----------------
Array(0=>1,1=>2)

Actual result:
--------------
Array(1=>2)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-02-24 14:26 UTC] derick@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php4-STABLE-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php4-win32-STABLE-latest.zip

Works fine for me...
 [2004-02-26 00:38 UTC] postings-php-bug at hans-spath dot de
I can't reproduce this under Windows XP (CLI) or Linux (Apache2 module). Version 4.3.4.
 [2004-03-08 07:11 UTC] sniper@php.net
This was already fixed some time ago.

 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Thu Apr 17 01:01:56 2014 UTC