php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61967 unset array item in array_walk_recursive cause inconsistent array
Submitted: 2012-05-07 02:33 UTC Modified: 2016-07-29 22:20 UTC
Votes:2
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: laruence@php.net Assigned: laruence (profile)
Status: Closed Package: Arrays related
PHP Version: 5.3.12 OS:
Private report: No CVE-ID: None
 [2012-05-07 02:33 UTC] laruence@php.net
Description:
------------
when you unset the array which you are iterating. array inconsistent will be 
reported.

I am looking into it, but sadly it is a little difficult to be fixed. since we 
also allow change the item in the iterator function.

thanks

Test script:
---------------
<?php
$arr = array(
    range(1, 10),
    range(1, 10),
    range(1, 10),
    range(1, 10),
    range(1, 10),
);

array_walk_recursive($arr,
    function (&$value, $key) use(&$arr) {
        unset($arr[$key]);
    });

Expected result:
----------------
nothing wrong

Actual result:
--------------
Zend/zend_hash.c(1085) : ht=0x25f5b78 is inconsistent

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-05-07 02:45 UTC] laruence@php.net
-Assigned To: +Assigned To: laruence
 [2012-05-07 02:57 UTC] laruence@php.net
and if someone can make a patch earlier than me, the patch will be appreciated.
 [2012-05-07 03:03 UTC] laruence@php.net
-Summary: unset array item cause inconsistent array +Summary: unset array item in array_walk_recursive cause inconsistent array
 [2013-07-29 21:00 UTC] mhitza at gmail dot com
Can be safely closed as it doesn't cause any problems on 5.5
 [2016-07-29 22:20 UTC] nikic@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 07:01:29 2024 UTC