php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31134 foreach() semantics broken between 4.3.9 and 4.3.10
Submitted: 2004-12-16 20:24 UTC Modified: 2004-12-16 21:17 UTC
Votes:6
Avg. Score:5.0 ± 0.0
Reproduced:4 of 4 (100.0%)
Same Version:4 (100.0%)
Same OS:2 (50.0%)
From: jlabonsk at eportation dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.3.10 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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jlabonsk at eportation dot com
New email:
PHP Version: OS:

 

 [2004-12-16 20:24 UTC] jlabonsk at eportation dot com
Description:
------------
The foreach($array as $key) construct returns an array for $key, instead of just the key. This breaks many scripts that count on $key being a scalar (and well, the key).


Reproduce code:
---------------
$test = array(2, 3, 4, 5);

foreach($test as $key){
	print_r($key);
}

Expected result:
----------------
2345

Actual result:
--------------
Array
(
    [0] => 2
    [1] => 0
)
Array
(
    [0] => 3
    [1] => 1
)
Array
(
    [0] => 4
    [1] => 2
)
Array
(
    [0] => 5
    [1] => 3
)


Patches

patch_6star (last revision 2010-09-03 16:51 UTC by info at 6stargrp dot com)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-12-16 20:36 UTC] jsjohnst@php.net
I can also confirm this is an issue.
 [2004-12-16 21:17 UTC] jsjohnst@php.net
Same issue as:
http://bugs.php.net/bug.php?id=31108

Upgrade Zend Optimizer and it fixes it.
 [2011-03-06 14:16 UTC] phuquangnam1 at gmail dot com
help
 [2011-04-01 17:43 UTC] varioseveral at gmail dot com
Hi.  In this moment the server update the sql, i have problems with my db, i can't export, import, add, etc.  What can i do for solve this problem?  Thanks
 [2022-01-29 12:53 UTC] aryasatvikkumar at gmail dot com
Shop Online from trendy apparels for women, men & kids at best prices. Select your favorite clothing from the fashionable collection on Satvik Kumar Arya clothing brands.
To get more info visit : https://satvikkumararya.com/
 [2024-02-18 20:47 UTC] rodiyansah406 at gmail dot com
Dana
 [2024-02-18 20:51 UTC] rodiyansah406 at gmail dot com
082184175348
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 05:01:30 2024 UTC