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

is_* with null coalesce on array value does not reduce the type #5304

Closed
BackEndTea opened this issue Jul 14, 2021 · 3 comments · Fixed by phpstan/phpstan-src#1707
Closed
Labels
Milestone

Comments

@BackEndTea
Copy link
Contributor

Bug report

When doing an is_string check on an array access, within an if with a null coalesce (in case the key is not present), does not make PHPStan understand that they key must be there.

Code snippet that reproduces the problem

https://phpstan.org/r/d3ff8430-a6ae-498a-b09e-fed774f9099d

Expected output

I expected both outputs to be Dumped type: array('foo' => string)

I know this isn't the best code, and an isset would've been better here, but i noticed this in our code base.

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Jul 14, 2021
@phpstan-bot
Copy link
Contributor

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

@@ @@
- 9: Dumped type: array(?'foo' => string)
-13: Dumped type: array('foo' => string)
+No errors

@phpstan-bot
Copy link
Contributor

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

@@ @@
- 9: Dumped type: array(?'foo' => string)
-13: Dumped type: array('foo' => string)
+ 9: Dumped type: array{foo?: string}
+13: Dumped type: array{foo: string}
Full report
Line Error
9 Dumped type: array{foo?: string}
13 Dumped type: array{foo: string}

@github-actions
Copy link

github-actions bot commented Oct 8, 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 Oct 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
3 participants