Bug #71233 [NEW]: th quote of array leads to the change of array

From: Date: Tue, 29 Dec 2015 08:40:41 +0000
Subject: Bug #71233 [NEW]: th quote of array leads to the change of array
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-198272@lists.php.net to get a copy of this message
From:             576932087 at qq dot com
Operating system: Red Hat 4.4.7-4
PHP version:      7.0Git-2015-12-29 (snap)
Package:          Arrays related
Bug Type:         Bug
Bug description:th quote of array leads to the change of array

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 bug report at https://bugs.php.net/bug.php?id=71233&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=71233&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=71233&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=71233&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=71233&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=71233&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=71233&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=71233&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=71233&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=71233&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=71233&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=71233&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=71233&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=71233&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71233&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=71233&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=71233&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=71233&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=71233&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=71233&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=71233&r=mysqlcfg



Thread (3 messages)

« previous php.bugs (#198272) next »