|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-06-08 13:12 UTC] 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) { }
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 22 17:00:01 2025 UTC |
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.