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
 [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: Thu Apr 25 01:01:30 2024 UTC