Bug #71421 [Opn->Nab]: Foreach with a reference is add content

From: Date: Wed, 20 Jan 2016 18:31:52 +0000
Subject: Bug #71421 [Opn->Nab]: Foreach with a reference is add content
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-198806@lists.php.net to get a copy of this message
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)

« previous php.bugs (#198806) next »