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.
- related to
-
PHPC-1006 Do not modify memory of Persistable::bsonSerialize() return value
- Closed
- links to