Skip to content

Commit dac877d

Browse files
committed
fix(support): handle null detection in contains()
Bug reproduction: ``` $result = contains([1, null, 3], null); // Returns false even though null exists in the array ```
1 parent 2ca75e9 commit dac877d

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

packages/support/src/Arr/functions.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -843,11 +843,12 @@ function has_key(iterable $array, int|string $key): bool
843843
*/
844844
function contains(iterable $array, mixed $search): bool
845845
{
846+
$array = to_array($array);
846847
$search = $search instanceof Closure
847848
? $search
848849
: static fn (mixed $value) => $value === $search;
849850

850-
return namespace\first(to_array($array), $search) !== null;
851+
return array_any($array, static fn ($value, $key) => $search($value, $key));
851852
}
852853

853854
/**

0 commit comments

Comments
 (0)