diff --git a/src/Illuminate/Collections/Arr.php b/src/Illuminate/Collections/Arr.php index 3cb9a2ca180a..c14465c6b3fa 100644 --- a/src/Illuminate/Collections/Arr.php +++ b/src/Illuminate/Collections/Arr.php @@ -195,6 +195,8 @@ public static function first($array, callable $callback = null, $default = null) foreach ($array as $item) { return $item; } + + return value($default); } foreach ($array as $key => $value) { diff --git a/tests/Support/SupportArrTest.php b/tests/Support/SupportArrTest.php index f87a36364b79..2c5f6c224e67 100644 --- a/tests/Support/SupportArrTest.php +++ b/tests/Support/SupportArrTest.php @@ -214,6 +214,13 @@ public function testFirst() $this->assertSame('bar', $value3); $this->assertSame('baz', $value4); $this->assertEquals(100, $value5); + + $cursor = (function () { + while (false) { + yield 1; + } + })(); + $this->assertNull(Arr::first($cursor)); } public function testJoin()