Bug #71421 [Com]: Foreach with a reference is add content

From: Date: Thu, 21 Jan 2016 08:31:39 +0000
Subject: Bug #71421 [Com]: Foreach with a reference is add content
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-198816@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 Comment by: msw at msw dot cz Reported by: msw at msw dot cz Summary: Foreach with a reference is add content Status: Not a bug Type: Bug Package: Arrays related PHP Version: 7.0.2 Block user comment: N Private report: N New Comment: Ok, I'll try use foreach more carefully. But I think it would be more logical to not change input variable. (If there is no imput ... no loop ... no reason create|use $b) Previous Comments: ------------------------------------------------------------------------ [2016-01-20 18:31:50] requinix@php.net $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. ------------------------------------------------------------------------ [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

« previous php.bugs (#198816) next »