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

[email protected] ("576932087 at qq dot com")
Newsgroups php.bugs
Message-ID <[email protected]>
Edit report at https://bugs.php.net/bug.php?id=71233&edit=1

 ID:                 71233
 User updated by:    576932087 at qq dot com
 Reported by:        576932087 at qq dot com
 Summary:            th quote of array leads to the change of array
-Status:             Open
+Status:             Closed
 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

 New Comment:

i know


Previous Comments:
------------------------------------------------------------------------
[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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.