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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
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: Thu May 02 18:01:32 2024 UTC