-
Notifications
You must be signed in to change notification settings - Fork 92
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
added switchable warning for comparison numbers and strings #292
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
i582
changed the title
added switchable warning for comparison numbers and strings
WIP: added switchable warning for comparison numbers and strings
Aug 18, 2021
i582
changed the title
WIP: added switchable warning for comparison numbers and strings
added switchable warning for comparison numbers and strings
Aug 18, 2021
i582
changed the title
added switchable warning for comparison numbers and strings
WIP: added switchable warning for comparison numbers and strings
Aug 18, 2021
i582
changed the title
WIP: added switchable warning for comparison numbers and strings
added switchable warning for comparison numbers and strings
Aug 23, 2021
AlexK0
reviewed
Aug 23, 2021
set_migration_php8_warning - Now this function accepts a bit mask where each bit sets the warnings to be triggered (currently for comparisons only) - Format strings are now created using template functions
Closed due #298 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In PHP 8, the logic for comparing numbers and strings has changed, so we need a way to find all such places, while not including warning at all, as this will lead to a huge number of warnings.
In order to enable the warning, the
set_migration_php8_warning
function has been added, with which you can enable or disable the warning. This function accepts a bitset, in which only the first right bit is used so far, but the rest will be used in the future.At the end of each request, the warning is automatically disabled.
Changes in
The operators
<=>
,==
,!=
,>
,>=
,<
, and<=
.The functions
in_array()
,array_search()
andarray_keys()
with$strict
set to false (which is the default).The sorting functions
sort()
,rsort()
,asort()
,arsort()
andarray_multisort()
with$sort_flags
set toSORT_REGULAR
(which is the default).Links
RFC: https://wiki.php.net/rfc/string_to_number_comparison
In documentation: String to Number Comparison
The following table shows how the result of some simple comparisons changes (or doesn't change) under this RFC:
0 == "0"
true
true
0 == "0.0"
true
true
0 == "foo"
true
false
0 == ""
true
false
42 == " 42"
true
true
42 == "42foo"
true
false
See full table in tests:
kphp/tests/cpp/runtime/number-string-comparison.cpp
Line 21 in d5a76ad
Note
We are already comparing infinities as in PHP 8.
See Special values part of RFC.
Related changes (not implemented in this PR, see #298)
In https://wiki.php.net/rfc/saner-numeric-strings (implemented in PHP 8):
Before
See VKCOM/kphp-polyfills#25
#290