More precise implode() return type#3774
Merged
ondrejmirtes merged 4 commits intophpstan:1.12.xfrom Mar 9, 2025
Merged
Conversation
Contributor
Author
|
//cc @VincentLanglet since its string accessory business :) |
staabm
commented
Jan 6, 2025
| } | ||
|
|
||
| $accessoryTypes = []; | ||
| $valueTypeAsString = $arrayType->getIterableValueType()->toString(); |
Contributor
Author
There was a problem hiding this comment.
the actual change is here: we use toString as the implode function internally casts everything.
that way the string types detection also works for unions of strings and non-strings (e.g. 2|'a') and so we get more precise results
b1fb846 to
fe52c9e
Compare
mvorisek
reviewed
Jan 7, 2025
75c4610 to
224d41d
Compare
8e351b9 to
3098f46
Compare
staabm
commented
Feb 15, 2025
| /** @param array{0: 1, 1: 'a'|'b', 3?: 'c'|'d', 4?: 'e'|'f', 5?: 'g'|'h', 6?: 'x'|'y'} $constArr */ | ||
| public function constArrays6($constArr) { | ||
| assertType("string", implode('', $constArr)); | ||
| assertType("literal-string&lowercase-string&non-falsy-string", implode('', $constArr)); |
Contributor
Author
There was a problem hiding this comment.
Memo to me: Literal string is wrong here
staabm
commented
Feb 22, 2025
Comment on lines
+17
to
+25
| if (str_contains($i, 0)) { | ||
| assertType('int', $i); | ||
| } | ||
| if (str_contains($s, 0)) { | ||
| assertType('non-empty-string', $s); | ||
| } | ||
| if (str_contains($s, 1)) { | ||
| assertType('non-falsy-string', $s); | ||
| } |
Contributor
Author
There was a problem hiding this comment.
these cases depends on strict-types.. are we still fine with it?
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.
No description provided.