From:             uli dot staerk at globalways dot net
Operating system: Linux
PHP version:      Irrelevant
Package:          Scripting Engine problem
Bug Type:         Bug
Bug description:foreach: Using variable reference leads to inconsistent data

Description:
------------
As you can see from the example, php seems to mix up variables if you use
the reference in a foreach.

Despite the report bug 43806, I still think this is a bug. The variable
must be set when calling foreach and must not be influenced by any previous
code.

Test script:
---------------
<?php
$testdata = array(
        0 => array('foo' => 'foo'),
        1 => array('bar' => 'bar')
);
foreach($testdata as &$value) {}
foreach($testdata as $key => $value) {
        if($key == 1) {
                print_r($value);
        }
}


Expected result:
----------------
Array
(
    [bar] => bar
)


Actual result:
--------------
Array
(
    [foo] => foo
)

-- 
Edit bug report at https://bugs.php.net/bug.php?id=63179&edit=1
-- 
Try a snapshot (PHP 5.4):   
https://bugs.php.net/fix.php?id=63179&r=trysnapshot54
Try a snapshot (PHP 5.3):   
https://bugs.php.net/fix.php?id=63179&r=trysnapshot53
Try a snapshot (trunk):     
https://bugs.php.net/fix.php?id=63179&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=63179&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=63179&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=63179&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=63179&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=63179&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=63179&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=63179&r=notwrong
Not enough info:            
https://bugs.php.net/fix.php?id=63179&r=notenoughinfo
Submitted twice:            
https://bugs.php.net/fix.php?id=63179&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=63179&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=63179&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=63179&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=63179&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=63179&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=63179&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=63179&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=63179&r=mysqlcfg

Reply via email to