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:
 [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)

Add a Patch

Pull Requests

Add a Pull Request

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
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Mon Apr 21 07:02:06 2014 UTC