diff --git a/system/Helpers/Array/ArrayHelper.php b/system/Helpers/Array/ArrayHelper.php index 2f219cfd6b38..7325922ad7f2 100644 --- a/system/Helpers/Array/ArrayHelper.php +++ b/system/Helpers/Array/ArrayHelper.php @@ -171,7 +171,13 @@ private static function hasByDotPath(array|object $array, array $indexes): bool $currentIndex = array_shift($indexes); if ($currentIndex === '*') { - foreach (self::entries($array) as $item) { + $entries = self::entries($array); + + if ($entries === []) { + return false; + } + + foreach ($entries as $item) { if (! self::isNavigable($item) || ! self::hasByDotPath($item, $indexes)) { return false; } diff --git a/tests/system/Helpers/Array/ArrayHelperDotHasTest.php b/tests/system/Helpers/Array/ArrayHelperDotHasTest.php index faccf7fe5ce3..5ae7fb882c67 100644 --- a/tests/system/Helpers/Array/ArrayHelperDotHasTest.php +++ b/tests/system/Helpers/Array/ArrayHelperDotHasTest.php @@ -73,5 +73,7 @@ public function testDotHasWithWildCard(): void $this->assertTrue(ArrayHelper::dotHas('contacts.*.1.age', $this->array)); $this->assertTrue(ArrayHelper::dotHas('contacts.*.0.name', $this->array)); $this->assertFalse(ArrayHelper::dotHas('contacts.*.1.name', $this->array)); + $this->assertFalse(ArrayHelper::dotHas('*.name', [])); + $this->assertFalse(ArrayHelper::dotHas('contacts.friends.*.name', ['contacts' => ['friends' => []]])); } }