|  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
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: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: abk at avatartechnology dot com
New email:
PHP Version: OS:


 [2004-02-24 13:25 UTC] abk at avatartechnology dot com
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];

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-02-24 14:26 UTC]
Please try using this CVS snapshot:
For Windows:

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]
This was already fixed some time ago.

PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Oct 21 14:03:38 2021 UTC