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

Greater > and Less Than < comparisons with non-numeric, non-string, non-resource types should report error #10833

Open
kkmuffme opened this issue Mar 15, 2024 · 1 comment · May be fixed by #10834

Comments

@kkmuffme
Copy link
Contributor

e.g. https://psalm.dev/r/e63cef6890 this is a redundant condition but isn't reported, or https://psalm.dev/r/29eb392672 which causes a PHP notice.

However there are tons of things one can do wrong with those operators:
https://www.php.net/manual/en/language.operators.comparison.php#language.operators.comparison.types
and it would take an immense amount of time to figure out all possible cases and all report them as separate errors.

As a first, I suggest to report all > and < operations that contain an array, object, probably even null and bool as possible error - and refine this if e.g. there are too many false positives for some cases (e.g. int|false > 100)

Copy link

I found these snippets:

https://psalm.dev/r/e63cef6890
<?php

$a = array();

if ( $a > PHP_INT_MAX ) {
    echo "yes";
}
Psalm output (using commit ef3b018):

No issues!
https://psalm.dev/r/29eb392672
<?php

$a = new stdClass();

if ( $a > PHP_INT_MAX ) {
    echo "yes";
}
Psalm output (using commit ef3b018):

No issues!

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