Edit report at https://bugs.php.net/bug.php?id=71241&edit=1
ID: 71241
Updated by: [email protected]
Reported by: [email protected]
Summary: array_replace_recursive sometimes mutates its
parameters
-Status: Open
+Status: Not a bug
Type: Bug
Package: Variables related
PHP Version: 7.0.1
Block user comment: N
Private report: N
New Comment:
close as not a bug.
Previous Comments:
------------------------------------------------------------------------
[2015-12-30 03:00:40] [email protected]
the new behavior is more correct, $arr1['k'] is a reference:
it behavior consistently with :
<?php
$one = [1];
$arr1 = ['k' => &$one];
$arr1['k'] = 2;
var_dump($one); //output 2
so, I think no bug here.
thanks
------------------------------------------------------------------------
[2015-12-30 00:03:23] [email protected]
The following patch has been added/updated:
Patch Name: fix_array_replace_recursive_ref_mut
Revision: 1451433803
URL: https://bugs.php.net/patch-display.php?bug=71241&patch=fix_array_replace_recursive_ref_mut&revision=1451433803
------------------------------------------------------------------------
[2015-12-30 00:03:02] [email protected]
Description:
------------
array_replace_recursive can sometimes mutate its params if references are nested within. This appears to be new behavior in PHP7. It also affects PHPunit.
Test script and diff: https://3v4l.org/0sdbm
Patch attached.
Test script:
---------------
<?php
$one = [1];
$two = [42];
$arr1 = ['k' => &$one];
$arr2 = ['k' => &$two];
var_dump(current($one), current($two));
array_replace_recursive($arr1, $arr2);
var_dump(current($one), current($two));
Expected result:
----------------
int(1)
int(42)
int(1)
int(42)
Actual result:
--------------
int(1)
int(42)
int(42)
int(42)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=71241&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.