php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31012 error with foreach
Submitted: 2004-12-07 17:46 UTC Modified: 2004-12-07 22:28 UTC
From: DeyV at php dot pl Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 4.3.10RC1 OS: win xp
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: DeyV at php dot pl
New email:
PHP Version: OS:

 

 [2004-12-07 17:46 UTC] DeyV at php dot pl
Description:
------------
In this version in foreach without $key parametr, the $value always is returned as array, when 
0 => value
1 => key 

Reproduce code:
---------------
$a = array (
    1 => 'test1', 
    2 => 'test2', 
    "three" => 1,
    "four"  => 2,
    "five"  => 3
);

foreach( $a as $v ) {
    print $v."\n";
}
var_dump( $v );


Expected result:
----------------
test test2 1 2 3 
int(3)

Actual result:
--------------
Array Array Array Array Array 
array(2) { [0]=>  int(3) [1]=>  string(4) "five" }

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-12-07 17:55 UTC] tony2001@php.net
Please, make sure that you disabled all Zend extensions (Zend Optimizer etc.) and try again.
 [2004-12-07 22:13 UTC] DeyV at php dot pl
Interesting. 
Without Zend Optimizer-2.5.5 this work correctly. 

Sorry.
 [2004-12-07 22:28 UTC] tony2001@php.net
Not a PHP bug -> bogus.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jun 09 20:01:26 2025 UTC