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
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 12:01:27 2024 UTC