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

Ensure array symtable converts to object proptable in PHP 7.2

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 1.2.10, 1.3.0-RC1, 1.3.0
    • Affects Version/s: 1.2.9, 1.3.0-beta1
    • Component/s: None
    • None

      According to the PHP 7.2 upgrade notes:

      • Casting arrays to objects (with (object) or settype()) will now convert integer keys to string property names. This fixes the behaviour of previous versions, where integer keys would become inaccessible properties with integer names.
      • Casting objects to arrays (with (array) or settype()), and retrieving object properties in an array with get_object_vars(), will now convert numeric string property names (that is, property names of the format /^(0|(-?[1-9][0-9]*))$/ where PHP_INT_MIN <= n <= PHP_INT_MAX) to integer keys. This fixes the behaviour of previous versions, where numeric string property names would become inaccessible string keys.

      When converting BSON to PHP, libbson's visitor functions build up an array. If the type map requests conversion to a PHP object, we then use with object_and_properties_init() to initialize a stdClass instance directly from that array's HashTable. This approach bypasses logic introduced in PHP 7.2 that converts keys from an array's symtable to an object proptable (and vice versa for object-to-array casts). Instead we should rely on convert_to_object(), which will convert keys as expected.

            Assignee:
            jmikola@mongodb.com Jeremy Mikola
            Reporter:
            jmikola@mongodb.com Jeremy Mikola
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: