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

Intval doesn't show RiskyCast error #11036

Open
jorgsowa opened this issue Jul 3, 2024 · 1 comment
Open

Intval doesn't show RiskyCast error #11036

jorgsowa opened this issue Jul 3, 2024 · 1 comment

Comments

@jorgsowa
Copy link
Contributor

jorgsowa commented Jul 3, 2024

https://psalm.dev/r/2af7638a7e

The behavior of (int) cast and intval() function should be the same, but only casting shows the error:

ERROR: RiskyCast - 3:13 - Casting non-empty-array<int|non-empty-string, array<int|non-empty-string, mixed>|string> to int has possibly unintended value of 0/1

Copy link

I found these snippets:

https://psalm.dev/r/2af7638a7e
<?php
if(isset($_GET['page'])) {
$a = (int) ($_GET['page']);

$b = intval($_GET['page']);
}
Psalm output (using commit 16b24bd):

ERROR: RiskyCast - 3:13 - Casting non-empty-array<int|non-empty-string, array<int|non-empty-string, mixed>|string> to int has possibly unintended value of 0/1

INFO: UnusedVariable - 3:1 - $a is never referenced or the value is not used

INFO: UnusedVariable - 5:1 - $b is never referenced or the value is not used

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant