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.
- is related to
-
PHPC-2245 Implement ArrayAccess for BSON PackedArray instances
- Closed