php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #11389 array_walk causes Apache to crash
Submitted: 2001-06-10 19:58 UTC Modified: 2002-03-24 22:32 UTC
From: sivev at hotmail dot com Assigned:
Status: Closed Package: Arrays related
PHP Version: 4.2.0-dev OS: ALL
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: sivev at hotmail dot com
New email:
PHP Version: OS:

 

 [2001-06-10 19:58 UTC] sivev at hotmail dot com
First, sorry, i have a very bad English.

This script:

$myarr = array(array(1,2,3), array(1,2,3), array(1,2,3));
array_walk(&$myarr, "myfunc");
function myfunc(&$value, $key) {
  global $myarr;
  $myarr=null;
}

causes Apache to crash. I'm using Apache 1.3.19 and PHP 4.0.4pl1 under W98.

Is a stupid script, but it's not the real script. Is the shorter script that reproduces the problem that i can send you.

thanks,
sive

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-06-10 20:32 UTC] sivev at hotmail dot com
I have installed PHP 4.0.5. The same problem ocurrs.
sive.
 [2001-06-23 17:29 UTC] sniper@php.net
Reproduced with PHP 4.0.6

 [2001-06-23 17:31 UTC] sbergmann@php.net
Reproduced with 4.0.7-dev (latest CVS, Win32)
 [2001-10-21 01:44 UTC] sniper@php.net
I can not reproduce this with PHP 4.1.0RC1.
Could you please try the latest development build from
http://www.php4win.com/

 [2001-11-11 06:49 UTC] sander@php.net
Reproduced with 4.2.0-dev (200111080300) on Windows 2000.

Array_walk seems to be pretty buggy. There were a few reports of crashes using array_walk, most importantly #12776.

Reopening.
 [2001-11-11 21:34 UTC] sniper@php.net
Indeed there is something odd going on:

<?php
$myarr = array(array(1,2,3), array(1,2,3), array(1,2,3));
echo "before\n";

array_walk($myarr, "myfunc");
function myfunc(&$value, $key) {
   global $myarr;
   $myarr=null;
}

echo "after\n";
?>

This script only echo's "before". 

--Jani

 [2001-11-12 18:13 UTC] venaas@php.net
Yes, what happens is that array_walk tries to move
forward to the next element by calling zend_hash_move_forward_ex() which determines that the
hash is inconsistent and bails out. I think this
behavior is good enough. This script is asking for
trouble. It's important that people can't crash Apache,
but I don't mind if weird scripts like this misbehaves.
CVS works okay for me since PHP doesn't crash, but bails
out. For me I get the same behavior if I remove the call
by references (in array_walk call and myfunc declaration).

 [2001-11-13 04:04 UTC] sivev at hotmail dot com
But this is not the real script!!

My real script have a lot of code lines and
functions, a lot of arrays inside other arrays
and so on, i need 'walk' the arrays, and
array_walk crash my code sometimes.

To work around this bug, i have written my
'my_array_walk' function in PHP script that
always behave OK.

I don't need the 'array_walk' function, but
i think this bug must be fixed.
 [2001-11-16 02:52 UTC] derick@php.net
It's not critical, cause it does not crash PHP.
 [2002-02-26 21:42 UTC] yohgaki@php.net
I know array walk has problem, but it's not simple to fix....
 [2002-03-24 22:32 UTC] yohgaki@php.net
I added comments to manual.

Users are not supposed to change array that is array_walk or array_filter is operating.

If you have an idea for feasible fix for this problem, feel free to reopen and fix this.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue May 06 02:01:28 2025 UTC