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

Empty check on array offset inside foreach loop is not treated as if it was an isset check #3784

Closed
ste93cry opened this issue Aug 26, 2020 · 4 comments
Labels
Milestone

Comments

@ste93cry
Copy link
Contributor

Bug report

The empty function is not treated as a !isset inside a foreach loop

Code snippet that reproduces the problem

This works: https://phpstan.org/r/c102939c-132d-44c9-a159-f93b35d83ac1
This doesn't works: https://phpstan.org/r/26cf5f07-d39c-4d81-bbd8-80850dc57411

Expected output

I expect no errors to be reported by PHPStan because empty also does an isset check

@mtorromeo
Copy link

It doesn't even matter if there is a foreach loop or not. empty checked on array offset don't seem to work like isset at all: https://phpstan.org/r/7fb590e6-2122-4f99-9ac3-66de38d7c0b1

@phpstan-bot
Copy link
Contributor

@ste93cry After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-21: Offset 'host' does not exist on array(?'scheme' => string, ?'host' => string, ?'port' => int, ?'user' => string, ?'pass' => string, ?'path' => string, ?'query' => string, ?'fragment' => string).
+No errors

@phpstan-bot
Copy link
Contributor

@mtorromeo After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-6: Offset 'test' does not exist on array(?'test' => string).
+No errors

@github-actions
Copy link

github-actions bot commented Aug 5, 2021

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 Aug 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants