Bug #72946 [Fbk->NoF]: variable assignment failure with foreach after reference

From: Date: Sun, 04 Sep 2016 04:22:25 +0000
Subject: Bug #72946 [Fbk->NoF]: variable assignment failure with foreach after reference
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-203777@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=72946&edit=1 ID: 72946 Updated by: php-bugs@lists.php.net Reported by: shaveneLee at gmail dot com Summary: variable assignment failure with foreach after reference -Status: Feedback +Status: No Feedback Type: Bug Package: *General Issues Operating System: Windows 10 or Centos 6.8 PHP Version: 7.0.10 Private report: N New Comment: No feedback was provided. The bug is being suspended because we assume that you are no longer experiencing the problem. If this is not the case and you are able to provide the information that was requested earlier, please do so and change the status of the bug back to "Re-Opened". Thank you. Previous Comments: ------------------------------------------------------------------------ [2016-08-26 10:06:00] laruence@php.net from https://3v4l.org/CafJM , I don't see the problem, do you have any thirdpart extension loaded which may affect the behavior? ------------------------------------------------------------------------ [2016-08-26 09:28:19] shaveneLee at gmail dot com Description: ------------ same array variable($reqs) when it was assign value with &, then use foreach to loop it again, the last loop variable value was assigned failed. please,see the simple test script below. Test script: --------------- function foo() { $reqs = array('11', '22', array('id' => 123, 'name' => 'ffff')); foreach ($reqs as &$req) { if (is_array($req)) { $req['name'] = 'dd'; //alter value } } echo '<pre>'; print_r($reqs); //values changed, ok echo '</pre>'; foreach ($reqs as $req) { echo '<pre>'; print_r($req); //the last value is '22', that is wrong. echo '</pre>'; } } output: 11 22 22 //it should be output this: array('id' => 123, 'name' => 'ffff') Expected result: ---------------- expect output result: 11 22 Array ( [id] => 123 [name] => ffff ) Actual result: -------------- 11 22 22 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=72946&edit=1

« previous php.bugs (#203777) next »