-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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
PHP 7.4 Warning for string to number comparisons that may change #3917
Conversation
Results for running this on the Laravel test suite:
|
Results for running this against pear-core tests (as a representative of a much older codebase):
|
Results for running against symfony tests (I get many baseline errors, but this is the only new one):
This is because trailing whitespace is not allowed in numeric strings. Something that's the case right now, but we should change this prior to making these comparison semantics changes. |
As PHP 7.4 has been released long ago, this PR is no longer relevant... |
While the comparison result changes, the equality comparison is not going to care about it in the end.
38493a0
to
b2350cc
Compare
Reopened this to rebase, closing again... |
Thanks, I did some tests with it on one of our largest projects, and no warnings were shown 👌 |
Did this go anywhere? Something like deprecation message on comparisons result of which will change in 8.0 would help a lot when migrating legacy codebase to 8.0. In particular, I'm worried about |
For anyone still testing their code against this: it seems that opcache sometimes prevents the warning from being raised, so be sure to disable opcache. For example: with opcache enabled I only get one warning for this code instead of two:
|
If this can help, I made a Psalm plugin for such cases: https://github.com/orklah/psalm-insane-comparison . It's not failproof and it depends on your project type coverage, but it will find the obvious cases |
While this might work for some cases, I don't think static analysis is capable of covering such cases in general because sometimes it's hard or even impossible to derive a type statically as it might depend on runtime settings things such as, for example, |
Companion to #3886 for RFC https://wiki.php.net/rfc/string_to_number_comparison. This implements a warning in PHP 7.4 that is thrown if the comparison result will be different in PHP 8 (if the change is accepted). For now this is just an unconditional warning and also prints the compared values.