Bug #71421 [Opn->Nab]: Foreach with a reference is add content
Edit report at https://bugs.php.net/bug.php?id=71421&edit=1
ID: 71421
Updated by: requinix@php.net
Reported by: msw at msw dot cz
Summary: Foreach with a reference is add content
-Status: Open
+Status: Not a bug
Type: Bug
Package: Arrays related
PHP Version: 7.0.2
Block user comment: N
Private report: N
New Comment:
$a['b'] has to exist in order for $b to be a reference to something. If it does not exist
then PHP will create it.
Previous Comments:
------------------------------------------------------------------------
[2016-01-20 15:35:10] msw at msw dot cz
Description:
------------
Run foreach with references on non-existent array index, add this index
Test script:
---------------
$a = array();
foreach($a['b'] as &$b){;}
print_r($a);
Expected result:
----------------
Array ( )
Actual result:
--------------
Array ( [b] => )
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=71421&edit=1
Thread (3 messages)