#37744 [Opn->Bgs]: unseting an index on ArrayObject may modify the original array

From: Date: Mon, 19 Jun 2006 17:06:56 +0000
Subject: #37744 [Opn->Bgs]: unseting an index on ArrayObject may modify the original array
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-98509@lists.php.net to get a copy of this message
ID: 37744 Updated by: tony2001@php.net Reported By: eric dot daspet at survol dot net -Status: Open +Status: Bogus Bug Type: SPL related Operating System: MS Windows XP PHP Version: 5.1.4 New Comment: Code: <?php $array = array('foo' => 'bar') ; $object = new ArrayObject( $array ) ; unset($object['foo']); var_dump( $array ) ; ?> Output: array(0) { } Code: <?php $array = array('foo' => 'bar') ; $object = new ArrayObject( $array ) ; $object['foo'] = 1;; unset($object['foo']); var_dump( $array ) ; ?> Output: array(0) { } Note the "objeCt" and "objet" in your code. Previous Comments: ------------------------------------------------------------------------ [2006-06-08 13:12:37] eric dot daspet at survol dot net Description: ------------ Deleting an index in ArrayObjet also delete it from the original array *if and only if* ArrayObject was not modified. This may introduce bugs (unexpected deletion in the original array). Note: if modification of the original array is wanted behaviour, then we have the opposite bugs : - documentation does not says that the array in ArrayObject constructor is passed as reference - I we modify the value of some entry in ArrayObject, the the relation between ArrayObject and the original array is lost Reproduce code: --------------- <?php $array = array('foo' => 'bar') ; $object = new ArrayObject( $array ) ; // uncomment this for opposite behaviour // and loose the reference between $object and $array // $objet['foo'] = 'hello' ; unset($objet['foo']); var_dump( $array ) ; Expected result: ---------------- array(1) { ["foo"]=> string(3) "bar" } Actual result: -------------- array(0) { } ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=37744&edit=1

« previous php.bugs (#98509) next »