Bug #79459 [NEW]: foreach twice with(out) assignment error
| From: | fauvel dot marc at free dot fr | Date: | Wed, 08 Apr 2020 14:50:46 +0000 |
| Subject: | Bug #79459 [NEW]: foreach twice with(out) assignment error | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-226485@lists.php.net to get a copy of this message | ||
From: fauvel dot marc at free dot fr
Operating system: Dcoker (official)
PHP version: 7.4.4
Package: *General Issues
Bug Type: Bug
Bug description:foreach twice with(out) assignment error
Description:
------------
In the test script,
I expect $a to finish with [1, 1, 1] but the actual result is [1, 1, 2]
Now if i change in the second loop $b with $c, the problem solve
itself.
I think $b already exist so the second foreach dont recreate it.
And the second problem is that foreach dont iterate the second time (
[2, 2, 2] would have be a strange result but acceptable)
Test script:
---------------
<?php
$a = [0, 0, 0];
foreach($a as &$b)
$b = 1;
foreach($a as $b)
$b = 2;
print_r($a);
?>
Expected result:
----------------
$a = [1, 1, 1];
Actual result:
--------------
$a = [1, 1, 2];
--
Edit bug report at https://bugs.php.net/bug.php?id=79459&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=79459&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=79459&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=79459&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=79459&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=79459&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=79459&r=support
Expected behavior: https://bugs.php.net/fix.php?id=79459&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=79459&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=79459&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=79459&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=79459&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=79459&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=79459&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=79459&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=79459&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=79459&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=79459&r=mysqlcfg