Fix named argument parameter matching in getFunctionCallStackWithParameters#4791
Merged
ondrejmirtes merged 1 commit intophpstan:2.1.xfrom Jan 20, 2026
Merged
Conversation
…meters When processing function calls with named arguments, the parameter was incorrectly matched using positional index instead of argument name. This caused Scope::getFunctionCallStackWithParameters() to return the wrong parameter when: 1. Arguments were passed out of order using named syntax 2. A named argument was passed for an optional parameter while a required parameter was missing The fix matches parameters by name for named arguments before falling back to positional matching.
698ece3 to
5bd7008
Compare
janedbal
added a commit
to shipmonk-rnd/phpstan-rules
that referenced
this pull request
Jan 20, 2026
Refactor the rule to use Scope::getFunctionCallStackWithParameters() instead of relying on node processing order, which broke with PHPStan's fiber-based processing. The new implementation: - Uses scope's call stack to determine if callable is immediately invoked - Handles IIFEs (immediately invoked function expressions) separately - Properly resolves named arguments to correct parameters Note: There's a PHPStan bug with named argument parameter matching that affects edge cases. Fix: phpstan/phpstan-src#4791
ondrejmirtes
requested changes
Jan 20, 2026
| if (isset($parameters[$i])) { | ||
| $assignByReference = $parameters[$i]->passedByReference()->createsNewVariable(); | ||
| $parameterType = $parameters[$i]->getType(); | ||
| $matchedParameter = null; |
Member
There was a problem hiding this comment.
This fix is in a wrong place. processArgs gets $normalizedExpr which is output of ArgumentsNormalizer. The fix should be there.
5be9f41 to
5bd7008
Compare
Member
|
Thank you! |
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.
When processing function calls with named arguments, the parameter was incorrectly matched using positional index instead of argument name. This caused Scope::getFunctionCallStackWithParameters() to return the wrong parameter when:
The fix matches parameters by name for named arguments before falling back to positional matching.