|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24300 Itterative variable not editable in a for loop
Submitted: 2003-06-23 14:36 UTC Modified: 2003-06-29 21:19 UTC
Avg. Score:4.0 ± 1.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:1 (50.0%)
From: chris at chrisseaton dot com Assigned:
Status: No Feedback Package: Scripting Engine problem
PHP Version: 4.3.2 OS: Linux
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 — but make sure to vote on the bug!
Your email address:
Solve the problem:
5 + 32 = ?
Subscribe to this entry?

 [2003-06-23 14:36 UTC] chris at chrisseaton dot com
If you are in a "for" loop you can't modify the itterative variable. PHP seems to revert it the value at the start of the itteration.

This is standard behaviour for both C and Java. The PHP documentation does not forbid this, and the syntax suggests it is possible, so I assume this is a bug and not a design decision.

Reproduce code:
for ($n = 0; $n < 4; $n++)

   if ($n = 2)
      $n = 4;

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-06-23 14:41 UTC] chris at chrisseaton dot com
Eratta: Obviously, I mean "if ($n == 2)"
 [2003-06-23 22:04 UTC]
Please try using this CVS snapshot:
For Windows:

Works as expected with PHP versions 4.2.3, 4.3.1, 4.3.3-dev..

 [2003-06-29 21:19 UTC]
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.

PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Mon Mar 20 23:03:39 2023 UTC