Uploaded image for project: 'PHP Driver: Extension'
  1. PHP Driver: Extension
  2. PHPC-2420

Comparing Int64 instances requires casting

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 1.19.4
    • Affects Version/s: 1.19.4
    • Component/s: None
    • None
    • PHP Drivers
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      The compare handler for MongoDB\BSON\Int64 uses ZEND_COMPARE_OBJECTS_FALLBACK, which can be used to limit comparisons to objects of the same type. While this works for most of our classes, Int64 is special as we want to default to loose type comparisons. For example, new Int64(0) == 0 should always evaluate to true. This is currently true as the comparison handler resorts to casting the Int64 instance to the desired type, int in this case.

      This has the side effect of triggering a warning when comparing an Int64 instance with a value outside of the 32-bit range with an int on a 32-bit platform, as we're truncating the value during the cast. This should not be necessary, as we can internally work with 64-bit values and return the correct value without triggering a truncation warning.

            Assignee:
            andreas.braun@mongodb.com Andreas Braun
            Reporter:
            andreas.braun@mongodb.com Andreas Braun
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: