Bug #75483 [Opn->Nab]: array_replace_recursive will merge (not replace), when both values are arrays
| From: | requinix@php.net | Date: | Fri, 03 Nov 2017 15:16:43 +0000 |
| Subject: | Bug #75483 [Opn->Nab]: array_replace_recursive will merge (not replace), when both values are arrays | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-212436@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75483&edit=1
ID: 75483
Updated by: requinix@php.net
Reported by: gladykov at gmail dot com
Summary: array_replace_recursive will merge (not replace),
when both values are arrays
-Status: Open
+Status: Not a bug
Type: Bug
Package: Arrays related
PHP Version: 7.1.11
Block user comment: N
Private report: N
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
Well, yeah. Because it's recursive. Wouldn't be much point to a recursive function that
doesn't act recursively.
Perhaps you want to use the regular array_replace?
Previous Comments:
------------------------------------------------------------------------
[2017-11-03 15:08:32] gladykov at gmail dot com
Description:
------------
array_replace_recursive will merge (not replace) values, when both key values in original and
replacement matching key are arrays.
When one of values either in original key or replacement key is string, replacement will occur
properly.
Test script:
---------------
<?php
//If value of availableReport key will be string in $original OR $replacement
array_replace_recursive will work properly
$original = [
'availableReports' => ['InternalReview' => 'Internal Review'],
];
$replacements = [
'availableReports' => ['AppraisalRev' => 'Commercial Appraisal
Review']
];
//Will print both values in current implementation
print_r(array_replace_recursive($original, $replacements));
?>
Expected result:
----------------
Array
(
[availableReports] => Array
(
[AppraisalRev] => Commercial Appraisal Review
)
)
Actual result:
--------------
Array
(
[availableReports] => Array
(
[InternalReview] => Internal Review
[AppraisalRev] => Commercial Appraisal Review
)
)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75483&edit=1