Implement ArrayAccess for BSON PackedArray instances

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Fixed
    • Priority: 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?
    • None
    • None
    • None
    • None
    • None
    • None

      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];
      

              Assignee:
              Andreas Braun
              Reporter:
              Andreas Braun
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: