php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71233 th quote of array leads to the change of array
Submitted: 2015-12-29 08:40 UTC Modified: 2015-12-29 20:57 UTC
From: 576932087 at qq dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 7.0Git-2015-12-29 (snap) OS: Red Hat 4.4.7-4
Private report: No CVE-ID: None
 [2015-12-29 08:40 UTC] 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)
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-12-29 09:42 UTC] 576932087 at qq dot com
-Status: Open +Status: Closed
 [2015-12-29 09:42 UTC] 576932087 at qq dot com
i know
 [2015-12-29 20:57 UTC] requinix@php.net
-Status: Closed +Status: Not a bug
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 02:01:29 2024 UTC