Bug #73622 [Opn->Nab]: Foreach iteration with a previously initialized variable
| From: | requinix@php.net | Date: | Wed, 30 Nov 2016 09:12:44 +0000 |
| Subject: | Bug #73622 [Opn->Nab]: Foreach iteration with a previously initialized variable | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-205691@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=73622&edit=1
ID: 73622
Updated by: requinix@php.net
Reported by: dorin dot marcoci at gmail dot com
Summary: Foreach iteration with a previously initialized
variable
-Status: Open
+Status: Not a bug
Type: Bug
-Package: PHP Language Specification
+Package: Scripting Engine problem
PHP Version: 7.0.13
Block user comment: N
Private report: N
New Comment:
Please take note of the big red warning in the documentation.
http://php.net/manual/en/control-structures.foreach.php
Previous Comments:
------------------------------------------------------------------------
[2016-11-30 09:09:03] dorin dot marcoci at gmail dot com
Description:
------------
Script below output A A instead of A B.
Is this as designed?
If I do unset($Item) before second foreach then it works as expected.
Test script:
---------------
<?php
$Items = [['Code' => 'A'], ['Item' => 'B']];
foreach ($Items as &$Item)
$Item['Hash'] = rand(1, 10);
foreach ($Items as $Item)
echo ' '.$Item['Code'];
Expected result:
----------------
A B
Actual result:
--------------
A A
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=73622&edit=1