PHPC-2420: Compare Int64 instances without casting #1617
Merged
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.
PHPC-2420
Previously, we deferred to
zend_std_compare_objects
when comparing a singleInt64
instance with a long or double. By default, this will attempt to cast values to long or double, then comparing it. On 32-bit platforms, this cast truncates any value outside of the 32-bit range and yields a warning about this truncation. This means that we were not able to properly compare such values, even when we technically would easily be able to (as only the value ofZEND_LONG
is limited to 32 bits, butint64_t
is still available).This PR changes this logic to specifically handle comparisons between to
Int64
instances as well as a singleInt64
instance with a long or double. Only if the instance is being compared with anything else will we attempt to cast the value. This removes warnings and fixes comparisons of 64-bit values on 32-bit platforms.