php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76793 While loop condition causes infinite execution
Submitted: 2018-08-25 15:43 UTC Modified: 2018-08-25 15:48 UTC
From: aimnexus12 at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 7.1.21 OS: Windows NT 6.2 build 9200
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
19 + 9 = ?
Subscribe to this entry?

 
 [2018-08-25 15:43 UTC] aimnexus12 at gmail dot com
Description:
------------
Changing the order of execution for the condition variable will cause the while loop to execute forever

Test script:
---------------
$index = 0;
$max = 10;

while($index <= $max) {
    if($index == 5) {
        continue;
    }
    
    echo "step: {$index} / {$max} \r\n";
    $index++;
}


Expected result:
----------------
step: 0 / 10
step: 1 / 10 
step: 2 / 10 
step: 3 / 10 
step: 4 / 10 
step: 6 / 10 
step: 7 / 10 
step: 8 / 10 
step: 9 / 10 
step: 10 / 10 

Actual result:
--------------
Script execution is terminated due to hitting the 30 seconds execution limit

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-08-25 15:48 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2018-08-25 15:48 UTC] requinix@php.net
10  IF $index == 5 THEN GOTO 10
 [2018-08-25 15:49 UTC] fractalesque at gmail dot com
How do you expect the script to ever increment the index if it skips every time forever?

Eg, when doing the check, it will continue. On next loop it will still be 5, and continue. On next loop it will still be 5, and continue. On next loop it will still be 5, and continue. On next loop it will still be 5, and continue. On next loop it will still be 5, and continue. On next loop it will still be 5, and continue. 

you get the idea.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 18:01:32 2024 UTC