Bug #67266 [Opn->Csd]: array_merge exceeds maximum execution time

From: Date: Tue, 26 Dec 2017 12:06:18 +0000
Subject: Bug #67266 [Opn->Csd]: array_merge exceeds maximum execution time
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-213278@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=67266&edit=1

 ID:                 67266
 Updated by:         nikic@php.net
 Reported by:        eithed at gmail dot com
 Summary:            array_merge exceeds maximum execution time
-Status:             Open
+Status:             Closed
 Type:               Bug
 Package:            *General Issues
 Operating System:   *
 PHP Version:        5.4.28
-Assigned To:        
+Assigned To:        nikic
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[2016-01-08 22:17:07] tpunt@php.net

This appears to be fixed in PHP 7: https://3v4l.org/T37UF

------------------------------------------------------------------------
[2014-05-13 15:45:23] eithed at gmail dot com

Description:
------------
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:
---------------
<?php
 
   $array = array('a','b');
   $t = &$array;
 
   foreach($t as $value)
        if ($value == 'a')
            $t = array_merge($t, array('c'));
        else
            echo($value);
 
   var_dump($array);
 
?>

Expected result:
----------------
b

array
  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


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=67266&edit=1


Thread (3 messages)

« previous php.bugs (#213278) next »