-
-
Notifications
You must be signed in to change notification settings - Fork 863
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
Bug: Default Array keys aren't detected to be non-negative #8900
Comments
Hi @Leoniebra. I don't know why default array keys aren't detected to be non-negative, |
OH! Thanks a bunch, that's a little embarassing! |
|
@Leoniebra After the latest push in 1.10.x, PHPStan now reports different result with your code snippet: @@ @@
-PHP 8.0 – 8.2 (1 error)
+PHP 8.0 – 8.2
==========
-10: Match expression does not handle remaining value: int<-3, -1>
+No errors
PHP 7.2 – 7.4 (1 error)
==========
11: Syntax error, unexpected T_DOUBLE_ARROW on line 11 Full reportPHP 8.0 – 8.2No errors PHP 7.2 – 7.4 (1 error)
|
@Leoniebra After the latest push in 1.10.x, PHPStan now reports different result with your code snippet: @@ @@
-PHP 8.0 – 8.2 (1 error)
+PHP 8.0 – 8.2
==========
-10: Match expression does not handle remaining value: int<-3, -1>
+No errors
PHP 7.2 – 7.4 (1 error)
==========
11: Syntax error, unexpected T_DOUBLE_ARROW on line 11 Full reportPHP 8.0 – 8.2No errors PHP 7.2 – 7.4 (1 error)
|
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
Hello!
I noticed that phpstan 1.9.17 treats the keys of arrays that are initialized empty and filled via $array[] = $value as possibly negative integers when using foreach to iterate through the array.
(For me it occurred with an array generated by the TYPO3 Extbase ObjectStorage ->toArray() method). This led to a match expression on which phpstan required more cases than I expected to be necessary.
Code snippet that reproduces the problem
I tried reproducing the issue here. Declaring the key within the foreaach loop as a positive-int was the best approach to a solution I found, sadly it didn't work either tho.
https://phpstan.org/r/1ee9ce43-4954-4188-9ac8-6f780f9223dd
Expected output
I expect this snippet to generate no issues, for I am sure that the keys of this array are always greater than or equal to 0.
Did PHPStan help you today? Did it make you happy in any way?
It sure did! While discovering this issue, I also found a heap of correctly reported problems within our code. I'm creating this issue because I enjoy using this tool a lot :)
Thanks in advance everyone!
Best,
Leo (it / she)
The text was updated successfully, but these errors were encountered: