Uploaded image for project: 'PHP Driver: Library'
  1. PHP Driver: Library
  2. PHPLIB-157

Improve _id extraction for Serializable objects

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.0.0
    • Affects Version/s: 1.0.0-beta2
    • Component/s: None
    • None

      When inserting objects, BulkWrite::insert() only returns an ID if it needed to be generated. Otherwise, the userland library falls back to attempting to extra the ID from the inserted document, which may be an array or object.

      Objects implementing the BSON Serializable interface may not have a public _id property, which may lead to either of two error messages:

      • Undefined property: CLASSNAME::$_id
      • Cannot access protected property ::$_id

      While PHPC-382 will ultimately resolve this by changing BulkWrite::insert() to always return the inserted ID (not only when generated), a temporary workaround for Serializable instances requires that we invoke bsonSerialize() from userland and extract an "_id" key from the returned array or object.

            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: