php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33572 Behavior of foreach changed
Submitted: 2005-07-05 10:00 UTC Modified: 2005-07-05 10:05 UTC
From: daniel at bokko dot nl Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.3.11 OS: Gentoo linux 2.4.22
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: daniel at bokko dot nl
New email:
PHP Version: OS:

 

 [2005-07-05 10:00 UTC] daniel at bokko dot nl
Description:
------------
After updrade to php 4.3.11 (from 4.3.4) the behaviour of foreach changed.
When i do not specify a $key in the foreach statement, the value is wrong when it's an array.


Reproduce code:
---------------
<pre>
<?php

$array = array();
$array[0] = array('apple', 'banana', 'pear', 'grape');
$array[1] = array('apple', 'banana', 'pear', 'grape');

print_r($array);

echo "\n-----------------\n";
foreach($array AS $v) {
    print_r($v);
}

?>
</pre>


Expected result:
----------------
Array
(
    [0] => apple
    [1] => banana
    [2] => pear
    [3] => grape
)
Array
(
    [0] => apple
    [1] => banana
    [2] => pear
    [3] => grape
)

Actual result:
--------------
Array
(
    [0] => Array
        (
            [0] => apple
            [1] => banana
            [2] => pear
            [3] => grape
        )

    [1] => 0
)
Array
(
    [0] => Array
        (
            [0] => apple
            [1] => banana
            [2] => pear
            [3] => grape
        )

    [1] => 1
)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-07-05 10:05 UTC] derick@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.

.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 13:01:34 2025 UTC