To allow users to use BSON\PackedArray instances like array, the class should implement functionality similar to ArrayAccess. This would allow the following uses:
// Before $packedArray->get(0); // After $packedArray[0]; // Before $packedArray->has(0); // After isset($packedArray[0]);
Since instances of the class are a read-only, the following are expected to throw:
$packedArray[0] = 'foo'; $packedArray[] = 'foo'; unset($packedArray[0]);
Accessing invalid offsets should also throw (e.g. string offsets, negative values, out-of-bounds keys):
$packedArray['foo'];
$packedArray[-1];
- related to
-
PHPC-2246 Implement ArrayAccess and property access for BSON document instances
- Closed