Don't loose known offset-types in array_merge()
the result of array_merge will always contain all string keys we see along the way.
~~we can't reason about the values when not all arrays are constant, but we can remember the keys.~~
since string keys overwrite each other, we know the value of the last string keys in the chain.
of other string based offsets we at least know about their existance.
best reviewed with whitespaces ignored
Followup could be doing the same for
- the
+operator when merging arrays array_replace- spread operator
This pull request has been marked as ready for review.
I like this 👍 Before looking at the code I thought I'd solve this with HasOffsetValueType as well.
the result of
array_mergewill always contain all keys we see along the way.
This is not correct for int keys, as those will be renumbered. (This is the reason array_replace() was added.)
https://3v4l.org/2h5Qn
@claudepache thanks - I also realized it. Adjusted the PR accordingly, please have another look
This pull request has been marked as ready for review.
Could it solve https://github.com/phpstan/phpstan/issues/13805 ?
Could it solve phpstan/phpstan#13805 ?
there is no array_merge call in this issue. but I think we might be able to apply a similar logic for this case.
there are even more use-cases see the PR description (just added spread operator to the list).
Looking at this I think we should add Type->getOffsetTypes() which returns a array of all known offsets of a type (const-ints/string), no matter its known by keys (const array), or by additional accessories.
This would ease building logic on top of it without the need for checking individual type classes