PHP Bugs  
php.net | support | documentation | report a bug | advanced search | search howto | statistics | login

go to bug id or search bugs for  

Bug #31134 foreach() semantics broken between 4.3.9 and 4.3.10
Submitted:16 Dec 2004 8:24pm UTC Modified: 16 Dec 2004 9:17pm UTC
From:jlabonsk at eportation dot com Assigned to:
Status:Bogus Category:Scripting Engine problem
Version:4.3.10 OS:Linux
Votes:6 Avg. Score:5.0 ± 0.0 Reproduced:4 of 4 (100.0%)
Same Version:4 (100.0%) Same OS:2 (50.0%)
View/Vote Developer Edit Submission

[16 Dec 2004 8:24pm 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
)

[16 Dec 2004 8:36pm UTC] jsjohnst@php.net
I can also confirm this is an issue.
[16 Dec 2004 9:17pm UTC] jsjohnst@php.net
Same issue as:
http://bugs.php.net/bug.php?id=31108

Upgrade Zend Optimizer and it fixes it.

RSS feed | show source 

PHP Copyright © 2001-2009 The PHP Group
All rights reserved.
Last updated: Sat Nov 21 10:30:49 2009 UTC