Skip to content

[13.x] Restore iterable support to Arr::every() and Arr::some()#60876

Merged
taylorotwell merged 1 commit into
laravel:13.xfrom
Amirhf1:fix/arr-every-some-iterables
Jul 24, 2026
Merged

[13.x] Restore iterable support to Arr::every() and Arr::some()#60876
taylorotwell merged 1 commit into
laravel:13.xfrom
Amirhf1:fix/arr-every-some-iterables

Conversation

@Amirhf1

@Amirhf1 Amirhf1 commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Arr::every() and Arr::some() document support for iterable values, but currently pass them directly to array_all() and array_any(), which only accept arrays.
As a result, passing an ArrayIterator, generator, or other non-array iterable throws a TypeError.
This change retains the native PHP helpers for arrays while restoring the original short-circuiting iteration behavior for other iterables.
Regression tests also ensure callback values and keys are passed correctly.

Comment on lines +597 to +607
if (is_array($array)) {
return array_all($array, $callback);
}

foreach ($array as $key => $value) {
if (! $callback($value, $key)) {
return false;
}
}

return true;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be enough to call Arr::from() on the input before passing it to array_all()?

Suggested change
if (is_array($array)) {
return array_all($array, $callback);
}
foreach ($array as $key => $value) {
if (! $callback($value, $key)) {
return false;
}
}
return true;
return array_all(self::from($array), $callback);

@taylorotwell
taylorotwell merged commit 78249d3 into laravel:13.x Jul 24, 2026
55 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants