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_array() type specification not working on variable declared in condition #3446

Closed
dktapps opened this issue Jun 10, 2020 · 4 comments
Closed

Comments

@dktapps
Copy link
Contributor

dktapps commented Jun 10, 2020

Bug report

It's hard to concisely describe this problem. The code can better explain.

Code snippet that reproduces the problem

https://phpstan.org/r/795b5a8b-9f34-438a-af37-14977d111516

Expected output

An error should be reported on L15 because I'm passing an array to a function which accepts string.

When checkExplicitMixed is set to true, both L14 and L15 complain about passing mixed as parameter, so the type inference is clearly not working correctly here.

@ondrejmirtes
Copy link
Member

Yeah, these styles of conditions are problematic. Use much more readable: https://phpstan.org/r/f2ed55be-f53f-4957-ac31-d01ad3c052f2

@phpstan-bot
Copy link
Contributor

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

@@ @@
-No errors
+15: Parameter #1 $s of method HelloWorld::takesString() expects string, array given.
Full report
Line Error
15 Parameter #1 $s of method HelloWorld::takesString() expects string, array given.

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@b2bf703

ondrejmirtes added a commit to phpstan/phpstan-src that referenced this issue May 11, 2021
@github-actions
Copy link

github-actions bot commented Jun 9, 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 Jun 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants