php.net |  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
Votes:2
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
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: chris at chrisseaton dot com
New email:
PHP Version: OS:

 

 [2003-06-23 14:36 UTC] chris at chrisseaton dot com
Description:
------------
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++)
{
   print("$n\n");

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

Expected result:
----------------
0
1
2

Actual result:
--------------
0
1
2
3

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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] sniper@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php4-STABLE-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php4-win32-STABLE-latest.zip


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

 [2003-06-29 21:19 UTC] sniper@php.net
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-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 13:01:28 2024 UTC