Skip to content

Commit 16388ed

Browse files
committed
Fix bug when merging an array with a non-array
1 parent 3824b8a commit 16388ed

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/Util.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static function mergeAssocArray($to, $from, int $mode = DataInterface::RE
4747
return array_merge($to, $from);
4848
}
4949

50-
if (is_array($from)) {
50+
if (is_array($from) && is_array($to)) {
5151
foreach ($from as $k => $v) {
5252
if (!isset($to[$k])) {
5353
$to[$k] = $v;

tests/UtilTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,13 @@ public function mergeAssocArrayProvider()
126126
[
127127
'Arrays should be merged/appended (when using MERGE)',
128128
// to
129-
['a' => 1, 'b' => 1, 'n' => [1]],
129+
['a' => 1, 'b' => 1, 'n' => [1], 'x' => 'string', 'y' => ['stringindex' => 1]],
130130
// from
131-
['a' => 2, 'c' => 2, 'n' => [2]],
131+
['a' => 2, 'c' => 2, 'n' => [2], 'x' => ['array'], 'y' => [2]],
132132
// mode
133133
DataInterface::MERGE,
134134
// expected result
135-
['a' => 2, 'b' => 1, 'c' => 2, 'n' => [1, 2]]
135+
['a' => 2, 'b' => 1, 'c' => 2, 'n' => [1, 2], 'x' => ['array'], 'y' => ['stringindex' => 1, 0 => 2]]
136136
],
137137
];
138138
}

0 commit comments

Comments
 (0)