|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66238 Unexpected behavior in for loop
Submitted: 2013-12-05 10:15 UTC Modified: 2013-12-05 16:37 UTC
From: gnjagi at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: Irrelevant OS:
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.
Block user comment
Status: Assign to:
Bug Type:
From: gnjagi at gmail dot com
New email:
PHP Version: OS:


 [2013-12-05 10:15 UTC] gnjagi at gmail dot com
For loop with $i zero padded gives unexpected behaviour

Test script:
echo $i."<br/>";
echo "<br/>";
echo $i."<br/>";
echo "<br/>";
echo $i."<br/>";

Expected result:
The $i value is not what is stated in the for loop

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-12-05 12:17 UTC] phpmpan at mpan dot pl
Please stick to bug report template. What is the expected result?

As far as I can see (until I miss something) the linked (why linked instead of just providing the result?) output is exactly what is expected. There are three loops. First output values from 8 to 19, the second outputs values from 21 to 49 and the third: from 27 to 59. This is exactly what the code states and how it should work.
 [2013-12-05 12:27 UTC] gnjagii at gmail dot com
echo $i."<br/>";
expected is a loop with 10- 19

echo $i."<br/>";
expected is a loop with 25- 49

echo $i."<br/>";
expected is a loop with 33- 59

the actual result as you see in the link is something else
 [2013-12-05 13:30 UTC] gnjagi at gmail dot com
-Summary: Expected behavior in for loop +Summary: Unexpected behavior in for loop
 [2013-12-05 13:30 UTC] gnjagi at gmail dot com
Unexpected behavior in a for loop when a value is zero padded
 [2013-12-05 16:37 UTC]
-Status: Open +Status: Not a bug
 [2013-12-05 16:37 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

010 is an octal notation, so parsed as 8.
025 in octal is 21.
033 in octal is 27.

See also for the different integer notations.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Feb 22 10:01:28 2024 UTC