|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67266 array_merge exceeds maximum execution time
Submitted: 2014-05-13 15:45 UTC Modified: 2017-12-26 12:06 UTC
From: eithed at gmail dot com Assigned: nikic (profile)
Status: Closed Package: *General Issues
PHP Version: 5.4.28 OS: *
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.
Block user comment
Status: Assign to:
Bug Type:
From: eithed at gmail dot com
New email:
PHP Version: OS:


 [2014-05-13 15:45 UTC] eithed at gmail dot com
I've been working on updating the referenced array while in loop, when I encountered an issue with array_merge - basically the code below will run indefinitely. If you'll change the `$value == 'a'` to `$value == 'b'` the code will successfully finish (the issue will occur for any non-last element of array); 

While array_merge doesn't solve my initial issue (as it seems to be working on array copy), I don't think such behavior is valid.

Test script:
   $array = array('a','b');
   $t = &$array;
   foreach($t as $value)
        if ($value == 'a')
            $t = array_merge($t, array('c'));

Expected result:

  0 => string 'a' (length=1)
  1 => string 'b' (length=1)
  2 => string 'c' (length=1)

Actual result:
Fatal error: Maximum execution time of 30 seconds exceeded


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-01-08 22:17 UTC]
This appears to be fixed in PHP 7:
 [2017-12-26 12:06 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2017-12-26 12:06 UTC]
Closing per previous comment. In PHP 7 foreach by value will operate on a copy of the array, so this is no longer an infinite loop.
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Wed Dec 12 10:01:25 2018 UTC