Bug #80161 [NEW]: Iterating on key/value with reference (&) has unexpected side effect
| From: | g dot passault at gmail dot com | Date: | Tue, 29 Sep 2020 15:43:53 +0000 |
| Subject: | Bug #80161 [NEW]: Iterating on key/value with reference (&) has unexpected side effect | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-229271@lists.php.net to get a copy of this message | ||
From: g dot passault at gmail dot com
Operating system: Linux (Ubuntu 18.04)
PHP version: 7.4.10
Package: Arrays related
Bug Type: Bug
Bug description:Iterating on key/value with reference (&) has unexpected side effect
Description:
------------
For some reason, walking an array using keys and reference values (&),
even without doing anything with it and then walking it has an influence
if and only if the variable name is the same in both cases
Test script:
---------------
<?php
$array = [
'x' => 1,
'y' => 2,
'z' => 3
];
// This useless walk has an effect on below walk
foreach ($array as &$item) {}
// This will show 1 2 2 instead of 1 2 3
// If you use another name for $item variable, it will show 1 2 3
foreach ($array as $item)
{
echo $item."\n";
}
Expected result:
----------------
1
2
3
Actual result:
--------------
1
2
2
--
Edit bug report at https://bugs.php.net/bug.php?id=80161&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=80161&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=80161&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=80161&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=80161&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=80161&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=80161&r=support
Expected behavior: https://bugs.php.net/fix.php?id=80161&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=80161&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=80161&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=80161&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80161&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=80161&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=80161&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=80161&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=80161&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=80161&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=80161&r=mysqlcfg