Skip to content
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

[9.x] Arr::map - Fix map-by-reference w/ built-ins #42815

Merged
merged 2 commits into from
Jun 15, 2022
Merged

[9.x] Arr::map - Fix map-by-reference w/ built-ins #42815

merged 2 commits into from
Jun 15, 2022

Conversation

claudiodekker
Copy link
Contributor

@claudiodekker claudiodekker commented Jun 15, 2022

This PR fixes fallback support for map by-reference with built-in's such as strrev that do not accept more than one argument, making it slightly more flexible, predictable and forgiving in behavior, as in the majority of situations the $key argument is omitted/ignored by the developer anyway.

While some situations might remain unsolved for some built-ins (ones that have exactly 2 parameters), I think it's important to mention that in such situations the user would be better off with a different or lower-level method such as array_map instead, as Laravel's documentation clearly indicates that a $key arg is passed within the map method.


ArgumentCountError: strrev() expects exactly 1 argument, 2 given in [..]/Illuminate/Collections/Arr.php:558
Stack trace:
#0 [internal function]: strrev('usb', 0)

Closes #42789

@taylorotwell taylorotwell merged commit 15b4587 into laravel:9.x Jun 15, 2022
@claudiodekker claudiodekker deleted the map-reference-fix branch June 15, 2022 17:45
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.

Collection methods don't work with built-in PHP functions
2 participants