Repository navigation
Expand unpacked args into one value per array item - #7038
Open
SanderMuller wants to merge 1 commit into
Open
SanderMuller wants to merge 1 commit into
SanderMuller wants to merge 1 commit into
Conversation
staabm
force-pushed
the
unpacked-array-map-args
branch
from
November 12, 2026 06:38
a6dde2a to
ba5d370
Compare
An unpacked arg passes one value per item of its array. array_map() and immediately invoked closures typed it as one value, so the callback parameters and the return type of array_map() were wrong. Unpacking a general array also reported a false argument.type error. When the number of values is not known, the callback keeps the type from the signature and array_map() returns its declared type. When it is known, array_map() adds null for the shorter arrays, as it does for arrays that are not unpacked. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SanderMuller
force-pushed
the
unpacked-array-map-args
branch
from
November 12, 2026 18:35
ba5d370 to
8a53a0d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes phpstan/phpstan#15620
An unpacked arg passes one value per item of its array.
array_map()and immediately invoked closures typed it as one value. So the callback parameters and the return type ofarray_map()were wrong, and unpacking a general array reported a falseargument.typeerror.The new
UnpackedArgumentTypes::expand()turns the arg types into one type per position:These places use it:
ContextualClosureParameterResolver, forarray_map()callbacks and immediately invoked closures. A rest type becomes a variadic parameter.ParametersAcceptorSelectorandArrayMapParameterClosureTypeExtension. With a rest type, the callback keeps the type from the signature.ArrayMapFunctionReturnTypeExtension. With a rest type, it returns the declared type.When the expansion gives a known number of arrays,
array_map()now adds null for the shorter arrays. #6874 does the same for arrays that are not unpacked, but it skipped unpacked args.ContextualClosureParameterResolverandParametersAcceptorSelectorhave Turbo twins. Both C++ twins call the PHP helper.Reproducer from the issue, at level 8:
array{4, 5, 6}4|5|6array{1, 2}1non-empty-list<array{4, 5, 6}>non-empty-list<4|5|6>Parameter #1 $callback of function array_map expects (callable(): mixed)|null, Closure(int, int): int given.🤖 Generated with Claude Code