Bug #76349 [Com]: Spoils the original array

From: Date: Wed, 16 May 2018 19:14:38 +0000
Subject: Bug #76349 [Com]: Spoils the original array
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-215288@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76349&edit=1 ID: 76349 Comment by: spam2 at rhsoft dot net Reported by: arnowt at gmail dot com Summary: Spoils the original array Status: Open Type: Bug Package: *General Issues Operating System: Linux PHP Version: Irrelevant Block user comment: N Private report: N New Comment: to make it clear: you miss a unset between both loops, $v of the second one still points to the last item of the previous loop Previous Comments: ------------------------------------------------------------------------ [2018-05-16 19:11:39] spam2 at rhsoft dot net just don't use references until you understand their implications and you are really sure you gain something - given the php engine has a copy-on-write paradigm there are very few cases ------------------------------------------------------------------------ [2018-05-16 18:24:27] arnowt at gmail dot com Description: ------------ Портит исходный массив. Проверял на версии v5.6 и v7.2 Test script: --------------- $res=[1,2,3]; foreach($res as &$v){} print_r($res); foreach($res as $v){} print_r($res); Expected result: ---------------- Array ( [0] => 1 [1] => 2 [2] => 3 ) Array ( [0] => 1 [1] => 2 [2] => 3 ) Actual result: -------------- Array ( [0] => 1 [1] => 2 [2] => 3 ) Array ( [0] => 1 [1] => 2 [2] => 2 //!!!!!! ) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=76349&edit=1

« previous php.bugs (#215288) next »