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

in_array combined with enum does not properly detect the type #10201

Closed
momala454 opened this issue Nov 27, 2023 · 2 comments
Closed

in_array combined with enum does not properly detect the type #10201

momala454 opened this issue Nov 27, 2023 · 2 comments
Labels
Milestone

Comments

@momala454
Copy link

momala454 commented Nov 27, 2023

Bug report

When in_array contains an enum, it break type detection

Code snippet that reproduces the problem

https://phpstan.org/r/b9e500a3-e3a8-466f-a540-fe7b3eb8f9ed

Expected output

No error should be reported.
I'm not sure if we should consider that comparing to the only enum value possible also require to compare if the value is instanceof the enum

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

No response

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Nov 27, 2023
@phpstan-bot
Copy link
Contributor

@momala454 After the latest push in 1.11.x, PHPStan now reports different result with your code snippet:

@@ @@
-PHP 8.1 – 8.3 (2 errors)
+PHP 8.1 – 8.3 (1 error)
 ==========
 
-10: Parameter #1 $hello of function world expects string, string|null given.
-15: Parameter #1 $hello of function world expects string, Hello|string|null given.
+ 9: Instanceof between string and Hello will always evaluate to false.
 
 PHP 7.2 – 8.0 (1 error)
 ==========
 
  3: Syntax error, unexpected T_STRING on line 3
Full report

PHP 8.1 – 8.3 (1 error)

Line Error
9 Instanceof between string and Hello will always evaluate to false.

PHP 7.2 – 8.0 (1 error)

Line Error
3 Syntax error, unexpected T_STRING on line 3

Copy link

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 Dec 29, 2023
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

3 participants