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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
14 + 22 = ?
Subscribe to this entry?

 
 [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-2020 The PHP Group
All rights reserved.
Last updated: Wed Aug 12 07:01:25 2020 UTC