php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27721 array_walk crashes PHP when called recursively
Submitted: 2004-03-26 12:57 UTC Modified: 2004-03-26 14:05 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: madams at morcor dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.3.4 OS: windows 2000/2003 server
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: madams at morcor dot com
New email:
PHP Version: OS:

 

 [2004-03-26 12:57 UTC] madams at morcor dot com
Description:
------------
array_walk causes PHP to crash on Windows 2000/2003 server when called recursively.

Reproduce code:
---------------
Please see http://staff.morcor.com/~madams/tmp/bugs.php.net/2004-03-26.array_walk_bug.phps for the source that causes PHP on Windows 2000/2003 server crash.  The script also attempts to load an xml file.  An example XML file is located at
http://staff.morcor.com/~madams/tmp/bugs.php/net/2004-03-26.configuration.xml
Script depends on PEAR.php and PEAR Config.php

Expected result:
----------------
This code should parse the array created by PEAR::Config and define a constant for every value in the array that is not a) an array itself, b) an array with a key of '@' or c) an array that does not have an attribute (sub-array '@') constant marked 'FALSE'.

Actual result:
--------------
Script runs partially, stops and fails to terminate properly.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-03-26 13:43 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Recursive functions will overflow the stack, this is a 
known and unsupported functionality. 
 [2004-03-26 14:05 UTC] madams at morcor dot com
Interestingly enough this code works fine with PHP running in FreeBSD.  Why is that?  Any ideas?
 [2004-06-08 23:29 UTC] aaron dot hawley at uvm dot edu
I'd guess it has to do with FreeBSD == 'Good'.

Fortunately, there is a solution.  One just needs to create your own array_walk function (yes, PHP allows you to write functions!):


    function array_walk_r(&$array, $function, $data = null)
    {
        foreach ($array as $key => $value)
        {
            call_user_func_array($function,
                                 array($value, $key, $data));
            $array[$key] = $value;
        }
    } // end func array_walk_r

It's too bad the PHP folks can't support us more functional-minded folks.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 19:01:37 2025 UTC