|  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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
34 - 24 = ?
Subscribe to this entry?

 [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: Sun Oct 17 21:03:32 2021 UTC