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

Simplify updating overloaded events for extensions

    Details

    • Type: Improvement
    • Status: Closed (View Workflow)
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.2.0-dev, 3.2.0-b2
    • Fix Version/s: 3.2.1-RC1
    • Component/s: Events, Extensions
    • Labels:
      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.:

      Unable to find source-code formatter for language: php. Available languages are: actionscript, html, java, javascript, none, sql, xhtml, xml
      $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:

      Unable to find source-code formatter for language: php. Available languages are: actionscript, html, java, javascript, none, sql, xhtml, xml
      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.:

      Unable to find source-code formatter for language: php. Available languages are: actionscript, html, java, javascript, none, sql, xhtml, xml
      $event->offsetUpdate('foo', 'bar', 'hello');
      

        Attachments

          Activity

            People

            • Assignee:
              Marc Marc
              Reporter:
              VSE VSE
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: