Uploaded image for project: 'phpBB3'
  1. phpBB3
  2. PHPBB3-14557

Simplify updating overloaded events for extensions

    XMLWordPrintable

Details

    • Improvement
    • Status: Closed (View Workflow)
    • Minor
    • Resolution: Fixed
    • 3.2.0-dev, 3.2.0-b2
    • 3.2.1-RC1
    • Events, Extensions
    • None

    Description

      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');
      

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: