Skip to content
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

null coalesce inside is_string() on optional array key has issues #8076

Closed
JurgenvanF opened this issue Sep 28, 2022 · 4 comments · Fixed by phpstan/phpstan-src#1793
Closed
Labels
Milestone

Comments

@JurgenvanF
Copy link

Bug report

Code snippet that reproduces the problem

https://phpstan.org/r/f0b56620-fd83-4fd4-9c03-9e85afdfa2c3

Expected output

No errors

Did PHPStan help you today? Did it make you happy in any way?

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Sep 28, 2022
@herndlm
Copy link
Contributor

herndlm commented Oct 4, 2022

quick question about this one that confused me - the core problem is the combination of
a) phpstan resolving string when accessing the potential unset $in['maybe'] https://phpstan.org/r/16baf67e-2c9b-4018-af1a-b8ebbf3a7200
in combination with
b) the typespecifier specifying string for $in['maybe'] via is_string($in['maybe'] ?? null) which is no new info and therefore leads to ImpossibleCheckTypeHelper returning true

I'm not entirely sure if this should/can be fixed in the type specifying code or somewhere else. my initial idea was to make the scope resolve such unsafe offsets "correctly" (e.g. string|null), but that is surely wrong, right? that would break many many things I suppose

@herndlm
Copy link
Contributor

herndlm commented Oct 4, 2022

ok, I played around a bit and figured it out I think. of course changing how unsafe ArrayDimFetch expressions are resolved does not make sense. this should be fixable in the type specifier 😊

@ondrejmirtes
Copy link
Member

Fixed by phpstan/phpstan-src#1793

@github-actions
Copy link

github-actions bot commented Nov 5, 2022

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants