Skip to content

Detect more possibly-impossible offset #4164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: 2.1.x
Choose a base branch
from

Conversation

VincentLanglet
Copy link
Contributor

@ondrejmirtes
Copy link
Member

I feel like the error could always be reported on level 7+.

The difference is that the reportPossiblyUndefined... option is for offsets like string, but in this case this is about a union and one of the union parts never exists on the constant array so it'd be a good fit for L7+ without any extra option.

@VincentLanglet VincentLanglet changed the title Add non regression test Detect more possibly-impossible offset Jul 26, 2025
@VincentLanglet VincentLanglet marked this pull request as draft July 26, 2025 15:47
@VincentLanglet VincentLanglet force-pushed the test/1061 branch 5 times, most recently from a7c6f0b to a5db337 Compare July 26, 2025 17:00
@VincentLanglet
Copy link
Contributor Author

I feel like I'm near the solution but I have a question for you first @ondrejmirtes.

The integration test show the current situation, we have now duplicates errors

Offset int|object might not exist on array|string.
Possibly invalid array key type int|object.

I know how to fix it, but I just want to show you it's also the current behavior when reportPossiblyNonexistentGeneralArrayOffset or reportPossiblyNonexistentConstantArrayOffset is enabled:
https://phpstan.org/r/b61c0c45-acbf-4493-90d4-18bfdedb1bb8

Do you want me to fix it for all three cases ?

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.

Fails to detect possibly-impossible constant offset
2 participants