phpbb / epv

Extension Pre-Validator
GNU General Public License v2.0
9 stars 17 forks source link

Add support for short array syntax in event $vars #78

Closed AlfredoRamos closed 6 years ago

AlfredoRamos commented 6 years ago

Currently the php_exporter class checks for exactly array() for the event $vars variable.

https://github.com/phpbb/epv/blob/2797678c7d4cabe915445bbf2ee643e9b9179666/src/Events/php_exporter.php#L284

https://github.com/phpbb/epv/blob/2797678c7d4cabe915445bbf2ee643e9b9179666/src/Events/php_exporter.php#L313

So using the short array syntax ([], PHP >= 5.4) throws an error.

Fatal error: Can not find '$vars = array();'-line for event '{EVENT}' in file '{FILE}:{LINE}'. Are you using UNIX style linefeeds?

This works:

/**
 * Sample event.
 *
 * @event vendor.extension.event_name
 * @var int var1
 * @var array   var2
 * @since 1.0.0
 */
$vars = array(
    'var1',
    'var2',
);
extract($this->dispatcher->trigger_event('vendor.extension.event_name', compact($vars)));

This gives the fatal error:

/**
 * Sample event.
 *
 * @event vendor.extension.event_name
 * @var int var1
 * @var array   var2
 * @since 1.0.0
 */
$vars = [
    'var1',
    'var2',
];
extract($this->dispatcher->trigger_event('vendor.extension.event_name', compact($vars)));

Both examples are using a valid PHP code and considering that phpBB 3.2.x requires at least PHP 5.4, it should support the short syntax.

marc1706 commented 6 years ago

This was already fixed in the phpBB core and needs to be updated in EPV. See https://github.com/phpbb/phpbb/pull/4877 and https://github.com/phpbb/phpbb/pull/4988