Uploaded image for project: 'phpBB'
  1. phpBB
  2. PHPBB-14557

Simplify updating overloaded events for extensions

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Minor Minor
    • 3.2.1-RC1
    • 3.2.0-dev, 3.2.0-b2
    • Events, Extensions
    • None

      Currently it is very verbose for an extension to update an $event value, when that value is an array. If you try to update the value directly, you get an ugly error, ie:

      $event['foo']['bar'] = 'hello';
      

      Indirect modification of overloaded element of phpbb\event\data has no effect

      The workaround, is to assign the event to a temporary variable, update the temp variable and reassign it back to the event, i.e.:

      $temp = $event['foo'];
      $temp['bar'] = 'hello';
      $event['foo'] = $temp;
      

      I think we can add a method to our event/data class that can simplify things, something like:

      public function offsetUpdate($offset, $key, $value)
      {
      	$this->data[$offset][$key] = $value;
      }
      

      Then an extension can reduce those previous 3 lines of code to 1 line, i.e.:

      $event->offsetUpdate('foo', 'bar', 'hello');
      

            Marc Marc
            VSE Matt Friedman [X] (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: