Bug #71233 [Csd->Nab]: th quote of array leads to the change of array

From: Date: Tue, 29 Dec 2015 20:57:31 +0000
Subject: Bug #71233 [Csd->Nab]: th quote of array leads to the change of array
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-198289@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71233&edit=1 ID: 71233 Updated by: requinix@php.net Reported by: 576932087 at qq dot com Summary: th quote of array leads to the change of array -Status: Closed +Status: Not a bug Type: Bug Package: Arrays related Operating System: Red Hat 4.4.7-4 PHP Version: 7.0Git-2015-12-29 (snap) Block user comment: N Private report: N Previous Comments: ------------------------------------------------------------------------ [2015-12-29 09:42:33] 576932087 at qq dot com i know ------------------------------------------------------------------------ [2015-12-29 08:40:33] 576932087 at qq dot com Description: ------------ $data = [1,2,3]; foreach ($data as &$value) { } foreach($data as $value) { } var_dump($data); 在第二次foreach之后,通过xdebug打印的data显示结果: data: (refcount=1, is_ref=0)=array (0 => (refcount=1, is_ref=0)=1, 1 => (refcount=1, is_ref=0)=2, 2 => (refcount=2, is_ref=1)=2) Test script: --------------- $data = [1,2,3]; foreach ($data as &$value) { } foreach($data as $value) { } var_dump($data); Expected result: ---------------- array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } Actual result: -------------- array(3) { [0]=> int(1) [1]=> int(2) [2]=> &int(2) } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=71233&edit=1

« previous php.bugs (#198289) next »