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
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.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Sat May 18 17:01:33 2024 UTC