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 with possible missing values throws "will always evaluate to true" in strict mode #3892

Closed
faizanakram99 opened this issue Sep 28, 2020 · 5 comments
Labels
Milestone

Comments

@faizanakram99
Copy link

faizanakram99 commented Sep 28, 2020

Bug report

This code snip will not always be true as OrderSaved::$dtos might not contain ReceiptOrder since ReceiptOrder::fromOrder() can return null

if (\in_array(ReceiptOrder::class, $missingClasses, true)) {
}

Code snippet that reproduces the problem

https://phpstan.org/r/7b6a301e-f874-4dce-bcd5-1c54cd42e854

Expected output

No errors

@faizanakram99 faizanakram99 changed the title in_array with possible missing values is considered "will always evaluate to true" in strict mode in_array with possible missing values throws "will always evaluate to true" in strict mode Sep 28, 2020
@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Sep 30, 2020
@phpstan-bot
Copy link
Contributor

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

@@ @@
 PHP 7.4 – 8.0 (1 error)
 ==========
 
-63: Call to function in_array() with arguments 'ReceiptOrder', array<0|1, 'PickingOrder'|'ReceiptOrder'> and true will always evaluate to true.
+-1: Internal error: PHPStan\Rules\Methods\WrongCaseOfInheritedMethodRule::findMethod(): Argument #2 ($classReflection) must be of type PHPStan\Reflection\ClassReflection, null given, called in /var/task/vendor/phpstan/phpstan-strict-rules/src/Rules/Methods/WrongCaseOfInheritedMethodRule.php on line 40
+Run PHPStan with --debug option and post the stack trace to:
+https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md
 
 PHP 7.1 – 7.3 (3 errors)
 ==========
Full report

PHP 7.4 – 8.0 (1 error)

Line Error
-1 Internal error: PHPStan\Rules\Methods\WrongCaseOfInheritedMethodRule::findMethod(): Argument #2 ($classReflection) must be of type PHPStan\Reflection\ClassReflection, null given, called in /var/task/vendor/phpstan/phpstan-strict-rules/src/Rules/Methods/WrongCaseOfInheritedMethodRule.php on line 40Run PHPStan with --debug option and post the stack trace to:https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md

PHP 7.1 – 7.3 (3 errors)

Line Error
60 Syntax error, unexpected ',' on line 60
60 Syntax error, unexpected T_DOUBLE_ARROW on line 60
60 Syntax error, unexpected T_STRING, expecting T_PAAMAYIM_NEKUDOTAYIM on line 60

@phpstan-bot
Copy link
Contributor

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

@@ @@
 PHP 7.1 – 7.3 (3 errors)
 ==========
 
-60: Syntax error, unexpected ',' on line 60
+60: Syntax error, unexpected T_STRING, expecting T_PAAMAYIM_NEKUDOTAYIM on line 60
 60: Syntax error, unexpected T_DOUBLE_ARROW on line 60
-60: Syntax error, unexpected T_STRING, expecting T_PAAMAYIM_NEKUDOTAYIM on line 60
+60: Syntax error, unexpected ',' on line 60
Full report

PHP 7.4 – 8.0 (1 error)

Line Error
63 `Call to function in_array() with arguments 'ReceiptOrder', array<0

PHP 7.1 – 7.3 (3 errors)

Line Error
60 Syntax error, unexpected T_STRING, expecting T_PAAMAYIM_NEKUDOTAYIM on line 60
60 Syntax error, unexpected T_DOUBLE_ARROW on line 60
60 Syntax error, unexpected ',' on line 60

@phpstan-bot
Copy link
Contributor

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

@@ @@
-PHP 7.4 – 8.0 (1 error)
+PHP 7.4 – 8.0
 ==========
 
-63: Call to function in_array() with arguments 'ReceiptOrder', array<0|1, 'PickingOrder'|'ReceiptOrder'> and true will always evaluate to true.
+No errors
 
 PHP 7.1 – 7.3 (3 errors)
 ==========
Full report

PHP 7.4 – 8.0

No errors

PHP 7.1 – 7.3 (3 errors)

Line Error
60 Syntax error, unexpected ',' on line 60
60 Syntax error, unexpected T_DOUBLE_ARROW on line 60
60 Syntax error, unexpected T_STRING, expecting T_PAAMAYIM_NEKUDOTAYIM on line 60

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@4321374

@github-actions
Copy link

github-actions bot commented Apr 3, 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 Apr 3, 2022
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