-
-
Notifications
You must be signed in to change notification settings - Fork 888
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
Casting to int something that's already an int #3884
Comments
This bug report is missing a link to reproduction on phpstan.org. |
This is just a question of wrong Thanks. |
But the signature is not wrong? bindec can return a float or an int? |
Duh, sorry, wrong end of stick. |
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
This is a duplicate of #1251, but with a better use case.
phpstan reports
Casting to int something that's already an int
even when the something has a possibility of not being an int.In my case this occurs with bindec, which has a documented return type of
float|int
, and I need to guarantee that it's anint
, so I'm casting it (it's safe because I'm also limiting the input size to 3 hex chars, so it will never actually hit the overflow that would cause it to return afloat
).The cast is also needed for other type checkers such as psalm.
Code snippet that reproduces the problem
phpstan's opinion would be correct if it could know all possible values of
$chunk
, but that's hard to know. For exampleFFFFFFFFFFFFFFFF
would return an int from bindec, butFFFFFFFFFFFFFFFFF
would return a float.Expected output
No error
The text was updated successfully, but these errors were encountered: