|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2006-06-08 12:45 UTC] eric dot daspet at survol dot net
 Description:
------------
When a multidimentional superglobal is used to feed ArrayObjet, the first unset of a sub-index is ignored.
- it is ok with a "normal" array, I've seen this only with $_REQUEST and $_GET
- it is ok with $_GET as a simple array (one dimension)
- the second call to unset() succeed, either if is the exact same call or if I try to unset another index, only the first fails
Reproduce code:
---------------
<?php
// call the script with ?index[i]=1&index[j]=2
$ao = new ArrayObject( $_GET ) ;
unset( $ao['index']['i'] ) ;  // ignored
var_dump($ao) ;
unset( $ao['index']['j'] ) ; // ok
var_dump($ao) ;
unset( $ao['index']['i'] ) ; // ok
var_dump($ao) ;
Expected result:
----------------
object(ArrayObject)#1 (1) { 
    ["index"]=>  array(2) {
         ["i"]=>  string(1) "1"
         ["j"]=>  string(1) "2" 
    }
}
object(ArrayObject)#1 (1) { 
    ["index"]=>  array(1) {
         ["i"]=>  string(1) "1"
    }
}
object(ArrayObject)#1 (1) { 
    ["index"]=>  array(0) {
    }
}
Actual result:
--------------
object(ArrayObject)#1 (1) { 
    ["index"]=>  array(1) {
         ["j"]=>  string(1) "1"
    }
}
object(ArrayObject)#1 (1) { 
    ["index"]=>  array(0) {
    }
}
object(ArrayObject)#1 (1) { 
    ["index"]=>  array(0) {
    }
}
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 09:00:01 2025 UTC | 
At least i get the expected result using the following: marcus@zaphod /usr/src/PHP_5_2 $ php -r '$ao = new ArrayObject(array("index"=>array("i"=>42))); unset($ao["index"]["i"]); var_dump($ao);' make: `sapi/cli/php' is up to date. object(ArrayObject)#1 (1) { ["index"]=> array(0) { } }