Skip to content

[12.x] Make built-in functions be callable with collection callbacks whose parameter count doesn't fit #56525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

shaedrich
Copy link
Contributor

Problem

Built-in or internal functions, unlike userland functions, must be called with the proper number of arguments. Userland functions can discard additional arguments on their own.

(new Collection([1, 'foo']))->filter('is_string')); // TypeError: is_string() expects exactly 1 argument, 2 given

Solution

This PR introduces the internal wrapper utility for certain methods to align built-in function behavior with their userland counterparts, callback function calls with callables have to be wrapped in this function to not throw an exception.

(new Collection([1, 'foo']))->filter('is_string')); // ['foo']

@shaedrich shaedrich changed the title Make built-in functions be callable with collection callbacks whose parameter count doesn't fit [12.x] Make built-in functions be callable with collection callbacks whose parameter count doesn't fit Aug 3, 2025
@taylorotwell
Copy link
Member

Thanks for your pull request to Laravel!

Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include.

If applicable, please consider releasing your code as a package so that the community can still take advantage of your contributions!

shaedrich added a commit to shaedrich/framework that referenced this pull request Aug 3, 2025
taylorotwell pushed a commit that referenced this pull request Aug 4, 2025
* Add Arr::some() and Arr::every()

* Add tests for `Arr::some()` and `Arr::every()`

* Fix first-class callable for built-in function with argument count mismatch

because we can't have nice things like #56525
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.

2 participants