-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Unknown
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
PHP Drivers
-
None
-
None
-
None
-
None
-
None
-
None
This issue was initially reported on GitHub: https://github.com/mongodb/mongo-php-library/issues/1731
The issue here is that when deserialising BSON data that contains a __pclass property, nested data is deserialised before calling bsonUnserialize on the Persistable instance. When a type map is provided (such as when iterating a cursor), this deserialisation of nested data respects the type map.
However, when we deserialise BSON data for a command subscriber, there is no type map to apply, which means that the logic will behave differently. In the case reported in the ticket above, the OP was expecting the PHPLIB type map (which deserialises documents into a BSONDocument instance) and had their bsonUnserialize implementation access nested data using array offsets. When deserialising data for a command subscriber, this logic then failed as no type map was applied and nested documents were passed as stdClass instances.
There are two possible solutions here, both of which could be considered BC breaks:
- don't respect the __pclass property when decoding the command BSON for a command subscriber
- ignore the type map when deserialising nested data for a Persistable
All in all, the only viable fix for this may be to improve documentation and encourage people to not rely on both type maps and Persistable implementations, but rather always use one or the other. This is what I suggested OP do in this case as well.