By defining a Event Listener Provider without a priority level, the error "ArgumentCountError array_merge() does not accept unknown named parameters" is thrown for PHP >= 8.0
Current behavior
According to Intro mezzio Oauth2 in order to define a Event Listener one should use:
return [
'event_listeners' => [
// using a container service
[
\League\OAuth2\Server\RequestEvent::CLIENT_AUTHENTICATION_FAILED,
\My\Event\Listener\Service::class,
],
which are then handled in the "AuthorizationServerFactory" as:
where if no priority is defined (as in the example displayed in help page), priority defaults to: $priority = null
Then Emitter.php file from “league/event” (wich can be found here: Emitter.php) adds the listeners as
public function addListener($event, $listener, $priority = self::P_NORMAL)
{
$listener = $this->ensureListener($listener);
$this->listeners[$event][$priority][] = $listener;
$this->clearSortedListeners($event);
return $this;
}
where $priority would stay as null.
The problem is that in PHP >= 8.0, when a listener is triggered with “Emitter.php” file uses the function:
protected function getSortedListeners($event)
{
if (! $this->hasListeners($event)) {
return [];
}
$listeners = $this->listeners[$event];
krsort($listeners);
return call_user_func_array('array_merge', $listeners);
}
wich in turn throws an error:
"ArgumentCountError array_merge() does not accept unknown named parameters"
due to PHP 8.0 named parameters feature.
How to reproduce
Define a event listener,
return [
'event_listeners' => [
// using a container service
[
\League\OAuth2\Server\RequestEvent::CLIENT_AUTHENTICATION_FAILED,
\My\Event\Listener\UserAuthenticationFailedListener,
],
Create a simple event listener
namespace My\Event\Listener;
use League\Event\AbstractListener;
use League\Event\EventInterface;
use League\OAuth2\Server\Exception\OAuthServerException;
class UserAuthenticationFailedListener extends AbstractListener
{
public function handle(EventInterface $event)
{
echo "do something right there"; exit;
}
}
If client authentication fails and the event "\League\OAuth2\Server\RequestEvent::CLIENT_AUTHENTICATION_FAILED" is detected the error "ArgumentCountError array_merge() does not accept unknown named parameters" will be thrown
Expected behavior
Not throw the error and implement the code in the listener.
It is possible to disable the error just by defining a priority for each listener, as:
Bug Report
I think this issue is still present in mezzio/mezzio-authentication-oauth2 in 2.8.0
Aditional info: | league/event | 2.2.0 | league/oauth2-server | 8.4.0
Summary
By defining a Event Listener Provider without a priority level, the error "ArgumentCountError array_merge() does not accept unknown named parameters" is thrown for PHP >= 8.0
Current behavior
According to Intro mezzio Oauth2 in order to define a Event Listener one should use:
which are then handled in the "AuthorizationServerFactory" as:
where if no priority is defined (as in the example displayed in help page), priority defaults to: $priority = null
Then Emitter.php file from “league/event” (wich can be found here: Emitter.php) adds the listeners as
where $priority would stay as null.
The problem is that in PHP >= 8.0, when a listener is triggered with “Emitter.php” file uses the function:
wich in turn throws an error: "ArgumentCountError array_merge() does not accept unknown named parameters"
due to PHP 8.0 named parameters feature.
How to reproduce
Define a event listener,
Create a simple event listener
If client authentication fails and the event "\League\OAuth2\Server\RequestEvent::CLIENT_AUTHENTICATION_FAILED" is detected the error "ArgumentCountError array_merge() does not accept unknown named parameters" will be thrown
Expected behavior
Not throw the error and implement the code in the listener.
It is possible to disable the error just by defining a priority for each listener, as:
Another possible solution would be something like: