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
mt_rand
assumed to always return the same value
#4091
Comments
In some cases the results are entirely deterministic (pure). |
Should PHPStan have an annotation for pure and impure functions then, defaulting to impure? It seems to me that assuming functions are not pure by default would be safe, but the current assumption that functions are always pure is false and causes this issue. |
I guess the problem is coming from here: https://github.com/phpstan/phpstan-src/blob/master/resources/functionMetadata.php#L1271 |
I guess this will be fixed next time Ondrej updates phpstorm-stubs and regenerates the function metadata. |
@GKFX After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-5: Comparison operation ">" between int<4, max> and 3 is always true.
+No errors |
Fixed: phpstan/phpstan-src@d4edc59 |
Closes phpstan/phpstan#4588 Closes phpstan/phpstan#4091 Closes phpstan/phpstan#3382 Closes phpstan/phpstan#4177 Closes phpstan/phpstan#2288 Closes phpstan/phpstan#1157
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. |
Bug report
mt_rand
returns a random number. The second if statement in the below is therefore not redundant. However PHPStan reportsComparison operation ">" between int<4, max> and 3 is always true.
.Code snippet that reproduces the problem
https://phpstan.org/r/43bf48f4-947d-4d96-9fc1-33e25fde3adb
Expected output
No output expected. Arguably, PHPStan should never assume that functions return the same value when called twice with the same arguments, but as this is a standard-library random number function it seems particularly important.
The text was updated successfully, but these errors were encountered: