Skip to content

Commit 51f3af6

Browse files
committed
[Support] Fix Arr::array to return [] by default
1 parent 7bb0f55 commit 51f3af6

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/Illuminate/Collections/Arr.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public static function add($array, $key, $value)
6464
/**
6565
* Get an array item from an array using "dot" notation.
6666
*/
67-
public static function array(ArrayAccess|array $array, string|int|null $key, ?array $default = null): array
67+
public static function array(ArrayAccess|array $array, string|int|null $key, ?array $default = []): array
6868
{
6969
$value = Arr::get($array, $key, $default);
7070

tests/Support/SupportArrTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,13 @@ public function testItGetsAnArray()
664664
Arr::array($test_array, 'string');
665665
}
666666

667+
public function testItReturnsEmptyArrayForMissingKeyByDefault()
668+
{
669+
$data = ['name' => 'Taylor'];
670+
671+
$this->assertSame([], Arr::array($data, 'missing_key'));
672+
}
673+
667674
public function testHas()
668675
{
669676
$array = ['products.desk' => ['price' => 100]];

0 commit comments

Comments
 (0)