From 6d8bd662e0dfe8e07a67a52dcd8e8ddfe18761f1 Mon Sep 17 00:00:00 2001 From: Abdullah Al Noman Prince Date: Sat, 29 Nov 2025 03:09:04 +0600 Subject: [PATCH 1/2] Fix Arr::first for ArrayObject and other array-like values --- src/Illuminate/Collections/Arr.php | 2 ++ tests/Support/SupportArrTest.php | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/src/Illuminate/Collections/Arr.php b/src/Illuminate/Collections/Arr.php index e6586edd7f95..1b76a4662df1 100644 --- a/src/Illuminate/Collections/Arr.php +++ b/src/Illuminate/Collections/Arr.php @@ -271,6 +271,8 @@ public static function first($array, ?callable $callback = null, $default = null return value($default); } + $array = static::from($array); + $key = array_find_key($array, $callback); return $key !== null ? $array[$key] : value($default); diff --git a/tests/Support/SupportArrTest.php b/tests/Support/SupportArrTest.php index d47d2879614c..ba4019cc9980 100644 --- a/tests/Support/SupportArrTest.php +++ b/tests/Support/SupportArrTest.php @@ -376,6 +376,15 @@ public function testFirst() $this->assertNull(Arr::first($cursor)); } + public function testFirstWorksWithArrayObject() + { + $arrayObject = new ArrayObject([0, 10, 20]); + + $result = Arr::first($arrayObject, fn ($value) => $value === 0); + + $this->assertSame(0, $result); + } + public function testJoin() { $this->assertSame('a, b, c', Arr::join(['a', 'b', 'c'], ', ')); From 3096990b30b69528b70fc2512d7e86d958efe5e3 Mon Sep 17 00:00:00 2001 From: Abdullah Al Noman Prince Date: Sat, 29 Nov 2025 08:40:14 +0600 Subject: [PATCH 2/2] Update Arr::first docblock to mention iterable --- src/Illuminate/Collections/Arr.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Collections/Arr.php b/src/Illuminate/Collections/Arr.php index 1b76a4662df1..277b2d69187a 100644 --- a/src/Illuminate/Collections/Arr.php +++ b/src/Illuminate/Collections/Arr.php @@ -242,7 +242,7 @@ public static function exists($array, $key) } /** - * Return the first element in an array passing a given truth test. + * Return the first element in an iterable passing a given truth test. * * @template TKey * @template TValue