Skip to content

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Sep 28, 2025

closes phpstan/phpstan#12981

when merging, we should extract phpstan/phpstan#12981 (comment) into a new issue

@staabm staabm marked this pull request as ready for review September 28, 2025 11:58
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.


$this->analyse([__DIR__ . '/data/bug-12981.php'], [
[
'Offset array<int, int|string> might not exist on non-empty-array<bool|float|int|string>.',
Copy link
Contributor

@VincentLanglet VincentLanglet Sep 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like a good improvement would be to not have this error reported because it's already reported as a Invalid array key type.

https://phpstan.org/r/b4c81787-7c0b-46b3-b281-dd572ab6f8ac

But that's another issue, I'll a look at it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WIP #4385

@staabm staabm force-pushed the rand branch 3 times, most recently from 3ec87b1 to 55f50a0 Compare September 30, 2025 14:40
@VincentLanglet
Copy link
Contributor

I think that if you rebase your PR @staabm your tests won't give the same output

@VincentLanglet
Copy link
Contributor

For the record, the fact

Offset array<int, int|string> might not exist on non-empty-array<bool|float|int|string>

is not reported anymore is expected.

The offset is already reported by the InvalidKey rule.

@staabm
Copy link
Contributor Author

staabm commented Oct 2, 2025

For the record, the fact

Offset array<int, int|string> might not exist on non-empty-array<bool|float|int|string>

thanks

The offset is already reported by the InvalidKey rule.

I just put the test-cases additionally into InvalidKeyInArrayDimFetchRuleTest so we can see the overall picture.

error on line 39 und 41 still overlap, maybe thats something which can also be improved in a separate PR

@VincentLanglet
Copy link
Contributor

error on line 39 und 41 still overlap, maybe thats something which can also be improved in a separate PR

There are not fully overlapping.

  • Possibly invalid array key type array<int, int|string>|int|string. is about the invalid array key array<int, int|string>
  • Offset array<int, int|string>|int|string might not exist on non-empty-array<bool|float|int|string>. is about the fact that int|string might not exist on non-empty-array<bool|float|int|string> because you enabled reportPossiblyNonexistentGeneralArrayOffset. I assume this error disappear with reportPossiblyNonexistentGeneralArrayOffset = false.

@ondrejmirtes ondrejmirtes merged commit bb8faa8 into phpstan:2.1.x Oct 6, 2025
541 of 548 checks passed
@ondrejmirtes
Copy link
Member

Thank you.

@staabm staabm deleted the rand branch October 6, 2025 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

array_rand() - "offset might not exists"
4 participants