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

Implement ArrayAccess and property access for BSON document instances

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 1.17.0
    • Affects Version/s: None
    • Component/s: None
    • None
    • 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?

      To allow users to use BSON\Document instances like a standard PHP array or object, the class should implement functionality similar to ArrayAccess and magic accessors. This would allow the following uses:

      // Before
      $document->get('foo');
      // After
      $document['foo'];
      $document->foo;
      
      // Before
      $document->has('foo');
      // After
      isset($document['foo']);
      isset($document->foo);
      

      Since instances of the class are a read-only, the following are expected to throw:

      $document['foo'] = 'foo';
      $document->foo = 'foo';
      $document[] = 'foo';
      unset($document['foo']);
      unset($document->foo);
      

      Accessing non-existing keys should throw the same way as Document::get does.

            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: