Bug #79459 [Opn]: foreach twice with(out) assignment error
| From: | fauvel dot marc at free dot fr | Date: | Wed, 08 Apr 2020 14:52:21 +0000 |
| Subject: | Bug #79459 [Opn]: foreach twice with(out) assignment error | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-226486@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79459&edit=1
ID: 79459
User updated by: fauvel dot marc at free dot fr
Reported by: fauvel dot marc at free dot fr
Summary: foreach twice with(out) assignment error
Status: Open
Type: Bug
Package: *General Issues
-Operating System: Dcoker (official)
+Operating System: Docker (official)
PHP Version: 7.4.4
Block user comment: N
Private report: N
New Comment:
fix typo on os
Previous Comments:
------------------------------------------------------------------------
[2020-04-08 14:50:46] fauvel dot marc at free dot fr
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 this bug report at https://bugs.php.net/bug.php?id=79459&edit=1