php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31150 foreach doesn't work properly
Submitted: 2004-12-17 12:20 UTC Modified: 2004-12-17 12:28 UTC
From: cdk at nsk dot ru Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.3.10 OS: BSD
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: cdk at nsk dot ru
New email:
PHP Version: OS:

 

 [2004-12-17 12:20 UTC] cdk at nsk dot ru
Description:
------------
foreach ($array as $key => $value)

if $key is not specified in foreach syntax, then in php 4.3.9 foreach iterated through array values, but in 4.3.10 $value becomes an array in each iteration.


Reproduce code:
---------------
$array = array(1,2,3);
$res = array();
foreach ($array as $value)
  $res[] = $value;


Expected result:
----------------
expecting $res like array(1,2,3)

Actual result:
--------------
but $res is array(array(1,0), array(2,1), array(3,2))

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-12-17 12:28 UTC] edink@php.net
Do not file bugs when you have Zend extensions (zend_extension=)
loaded. Examples are Zend Optimizer, Zend Debugger, Turck MM Cache,
APC, Xdebug and ionCube loader.  These extensions often modify engine
behavior which is not related to PHP itself.

Upgrading ZendOptimizer will solve this.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 04 10:01:32 2024 UTC