Bug #71241 [Opn]: array_replace_recursive sometimes mutates its parameters
Edit report at https://bugs.php.net/bug.php?id=71241&edit=1
ID: 71241
Updated by: nikic@php.net
Reported by: as@php.net
Summary: array_replace_recursive sometimes mutates its
parameters
Status: Open
Type: Bug
Package: Variables related
PHP Version: 7.0.1
Block user comment: N
Private report: N
New Comment:
@laruence: But isn't array_replace_recursive() supposed to return a new array while leaving the
original arguments alone?
A more accurate version of your example would be
<?php
$one = [1];
$arr1 = ['k' => &$one];
$result = [];
$result['k'] = $arr1['k'];
$result['k'] = 2;
In which case $one would remain unchanged.
Imho this is a bug in the PHP 7 implementation and it should instead return the PHP 5 result.
Previous Comments:
------------------------------------------------------------------------
[2016-01-26 22:46:40] rasmus@php.net
Re-opened. This does seem like a real bug in array_merge_recursive()
------------------------------------------------------------------------
[2016-01-11 18:17:14] as@php.net
Thanks for checking it out laruence. In that case, is array_merge_recursive buggy? It
exhibits the old behavior: https://3v4l.org/NSa9S
There is also a related oddity illustrated here https://3v4l.org/sYutE which again only seems to affect
array_replace_recursive.
I can open separate bugs if that's easier to track, but I think it's all the same root
issue.
------------------------------------------------------------------------
[2015-12-30 03:01:15] laruence@php.net
close as not a bug.
------------------------------------------------------------------------
[2015-12-30 03:00:40] laruence@php.net
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] as@php.net
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
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=71241
--
Edit this bug report at https://bugs.php.net/bug.php?id=71241&edit=1
Thread (8 messages)