Skip to content

[TypeDeclaration] Skip several arrays in AddClosureParamTypeForArrayMapRector - #9040

Closed
TomasVotruba wants to merge 1 commit into
mainfrom
array-map-closure-param-multi-array
Closed

TomasVotruba wants to merge 1 commit into
mainfrom
array-map-closure-param-multi-array

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

With 2+ arrays, array_map() pads the shorter array with null. Typing the closure params from the array value types then breaks at runtime:

array_map(function ($value, $second) {
    return $second . $value;
}, ['a', 'b'], ['x']);

was changed to

array_map(function (string $value, string $second) {
    return $second . $value;
}, ['a', 'b'], ['x']);

which throws TypeError: Argument #2 ($second) must be of type string, null given - even without strict_types.

Fix: skip the array_map() call when it gets more than one array. Single-array calls are typed as before. The multi-array fixture cases are now skip fixtures.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant