php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35545 Bug with some syntaxes in for loops
Submitted: 2005-12-04 13:04 UTC Modified: 2005-12-04 14:28 UTC
From: kervala at jpopdb dot net Assigned:
Status: Not a bug Package: Variables related
PHP Version: 5.1.1 OS: Linux 2.4
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: kervala at jpopdb dot net
New email:
PHP Version: OS:

 

 [2005-12-04 13:04 UTC] kervala at jpopdb dot net
Description:
------------
For my site, I used a piece of code which always worked fine. (see below)

It's a simple PHP code using a "for" loop and variables manipulation.


Reproduce code:
---------------
for($i=date("Y")+1; $i>=1970; $years[$i] = $i--);
	
print_r($years);


Expected result:
----------------
In all previous PHP versions, it returned :

2006 => 2006,
2005 => 2005,
etc...


Actual result:
--------------
It now returns :

2005 => 2006,
2004 => 2005,
etc...


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-12-04 13:14 UTC] tony2001@php.net
The result of this code is unknown in all languages: 
$years[$i] = $i--;
 [2005-12-04 13:38 UTC] kervala at jpopdb dot net
If $i is set to 200:

$years[$i] = $i--;
=> "$years[200] = 200;" not "$years[200] = 199;"

I don't see where the code is unknown... It's valid in all languages...

By the way why this code always worked in previous versions if this is unknown code ? ;p

I suppose it's a regression.
 [2005-12-04 14:28 UTC] kervala at jpopdb dot net
Oops, sorry, tou didn't meant that's the code which was unknown but the result...

However, I always knew that the 3rd parameter of "for" were instructions and the return code wasn't used even if "$years[$i] = $i--" should return $i in my case.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 12:01:33 2025 UTC