|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42065 SPL ArrayObject does not use "copy-on-write"
Submitted: 2007-07-22 11:05 UTC Modified: 2007-07-23 07:45 UTC
From: a dot yamanoi at gmail dot com Assigned:
Status: Closed Package: SPL related
PHP Version: 5.2.3 OS: *
Private report: No CVE-ID: None
 [2007-07-22 11:05 UTC] a dot yamanoi at gmail dot com
When ArrayObject::offsetSet() method stores a new value into an array,
I expect ArrayObject to change only the array which is given as a constructor parameter.

However, if the array is copied from another array and unchanged,
ArrayObject will also change the another array.

I thought it was a "copy-on-write" problem.

thank you for any help
Please excuse my English, it isn't very good.

Reproduce code:
$base = array('key' => 'old value');

$copy = $base;
$ao = new ArrayObject($copy);
$ao['key'] = 'new value';

echo '$base["key"] = ', $base['key'], "\n";
echo '$copy["key"] = ', $copy['key'], "\n";
echo '$ao["key"] = ', $ao['key'], "\n";

Expected result:
$base["key"] = old value
$copy["key"] = new value
$ao["key"] = new value

Actual result:
$base["key"] = new value
$copy["key"] = new value
$ao["key"] = new value


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-07-22 15:34 UTC]
Please try using this CVS snapshot:
For Windows (zip):

For Windows (installer):

This might have already been fixed..
 [2007-07-23 07:45 UTC] a dot yamanoi at gmail dot com
Thank you very much for your prompt reply.

It is fixed in the latest snapshot.

> php -v
PHP 5.2.4-dev (cli) (built: Jul 23 2007 00:04:07)

Expected result:
$base["key"] = old value
$copy["key"] = old value   <--- (In my first entry, this line was wrong.)
$ao["key"] = new value

I can get the expected result!
Thank you very much for your time.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Tue Oct 19 09:03:37 2021 UTC