Skip to content

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

Merged
taylorotwell merged 2 commits into
laravel:9.xfrom
claudiodekker:map-reference-fix
Jun 15, 2022
Merged

[9.x] Arr::map - Fix map-by-reference w/ built-ins#42815
taylorotwell merged 2 commits into
laravel:9.xfrom
claudiodekker:map-reference-fix

Conversation

@claudiodekker

@claudiodekker claudiodekker commented Jun 15, 2022

Copy link
Copy Markdown
Contributor

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