Bug #74431 [Com]: foreach infinite loop

From: Date: Fri, 14 Apr 2017 15:01:33 +0000
Subject: Bug #74431 [Com]: foreach infinite loop
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-208553@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74431&edit=1 ID: 74431 Comment by: ekin at coproductivity dot com Reported by: onceatease at gmail dot com Summary: foreach infinite loop Status: Open Type: Bug Package: opcache Operating System: Ubuntu 12.04.5 LTS PHP Version: 7.1.2 Block user comment: N Private report: N New Comment: I was able to reproduce that it causes an infinite loop when in a function on versions above 7.1.0. Also it's not just php-fpm, can also see it behaves the same on cli. Opened a PR with failing test https://github.com/php/php-src/pull/2479 Previous Comments: ------------------------------------------------------------------------ [2017-04-14 14:27:30] pollita@php.net Disabling the opcacge optimizer makes this go away, so it's probably in the break/cont optimization. ------------------------------------------------------------------------ [2017-04-14 07:36:40] onceatease at gmail dot com The code should be included in the function function test(){ $arr = [1,2]; $j = 0; $cond = true; foreach ($arr as $i => $v){ while(1){ if($cond){ break; } } $j++; echo $j."<br>"; //if($j>100) break; } } test(); ------------------------------------------------------------------------ [2017-04-13 20:30:20] ekin at coproductivity dot com I cannot reproduce this with php-fpm on any of 7.1.2, 7.1.3 or 7.1.4 on Ubuntu 16.04 LTS, having opcache enabled. Which related opcache settings did you use? ------------------------------------------------------------------------ [2017-04-13 10:07:47] onceatease at gmail dot com exec correctly in php7.1.0 test without php7.1.3 ------------------------------------------------------------------------ [2017-04-13 10:02:02] onceatease at gmail dot com Description: ------------ foreach will infinite loop in php-fpm, in the case while condition is literal and if conditon is a variable(in both php7.1.2 and php7.1.4) Test script: --------------- $arr = [1,2]; $j = 0; $cond = true; foreach ($arr as $i => $v){ while(1){ if($cond){ break; } } $j++; echo $j."<br>"; //if($j>100) break; } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=74431&edit=1

« previous php.bugs (#208553) next »