Add key typehints to iterable functions#102
Open
annadamm-check24 wants to merge 3 commits into
Open
Conversation
nikic
reviewed
May 11, 2026
| * | ||
| * @template T | ||
| * @template U | ||
| * @template IterableValue |
Owner
There was a problem hiding this comment.
All the other ones use TKey/TValue, why the difference here?
Author
There was a problem hiding this comment.
Because we have 3 variables and it was difficult to understand the key/value of which it should be.
Do you have other suggestions? I have seen UKey, TValue, etc., but I personally find that hard to understand.
Author
There was a problem hiding this comment.
@nikic should I change it, or do you think this is still okay?
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.
Description
Currently, PHPStan cannot handle string array/iterable keys for
map,filter, and other functions, as they are not properly type hintedSolution
The same as is already done in
fromPairs,tap, etc., adding a@template TKeyExisting Psalm errors
There were, and still are psalm-errors after this PR. I did not fix the existing ones, as that would be out of scope. As far as I can see, I did not introduce new psalm errors.
Probably, the CI should be extended for phpstan + psalm and these errors be fixed. And maybe there should be Tests, if both PHPStan and Psalm are correctly working on code derived from this library (could already happen in tests by accident?)