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
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: aimnexus12 at gmail dot com
New email:
PHP Version: OS:

 

 [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: Fri Apr 19 20:01:29 2024 UTC