php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37742 first call to unset() fails with ArrayObjet on a multidimensionnal superglobal
Submitted: 2006-06-08 12:45 UTC Modified: 2006-07-18 01:00 UTC
From: eric dot daspet at survol dot net Assigned: helly (profile)
Status: No Feedback Package: SPL related
PHP Version: 5.1.4 OS: MS Windows XP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: eric dot daspet at survol dot net
New email:
PHP Version: OS:

 

 [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) {
    }
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-06-08 13:10 UTC] eric dot daspet at survol dot net
Well, sorry, I have put Actual Result and Expected result in the wrong order.
 [2006-06-19 18:17 UTC] tony2001@php.net
Valgrind also reports several errors in this code:
<?php
$ao = new ArrayObject( $_GET ) ;
unset( $ao['index']['i'] ) ;
?>

==2182== Invalid read of size 4
==2182==    at 0x82151BC: _zval_ptr_dtor (zend_execute_API.c:393)
==2182==    by 0x821E7D8: _zval_ptr_dtor_wrapper (zend_variables.c:175)
==2182==    by 0x822818A: zend_hash_destroy (zend_hash.c:521)
==2182==    by 0x821E9EC: _zval_dtor_func (zend_variables.c:43)
==2182==    by 0x82151FD: _zval_ptr_dtor (zend_variables.h:35)
==2182==    by 0x821E7D8: _zval_ptr_dtor_wrapper (zend_variables.c:175)
==2182==    by 0x8227EA8: zend_hash_apply_deleter (zend_hash.c:576)
==2182==    by 0x82280A6: zend_hash_graceful_reverse_destroy (zend_hash.c:642)
==2182==    by 0x821760C: shutdown_executor (zend_execute_API.c:221)
==2182==    by 0x821F5C6: zend_deactivate (zend.c:854)
==2182==    by 0x81E6E94: php_request_shutdown (main.c:1300)
==2182==    by 0x8288B65: main (cgi_main.c:1667)
etc...
 [2006-07-10 01:01 UTC] helly@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip

The $__GET if still present is most likely related to super global handling.
 [2006-07-10 01:02 UTC] helly@php.net
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) {
  }
}
 [2006-07-18 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC