Problem/Motivation
This ticket is basically
https://www.drupal.org/project/drupal/issues/3174022 โ
but it's another place in the code making problems.
I just checked my Drupal instance's compatibility with PHP 8.1. it works quite well so far. Only one thing doesn't work, yet. I did some debugging and found the issue in the core:
web/core/lib/Drupal/Core/Extension/ModuleHandler.php
Here we have calls of call_user_func_array but the args are not processed with array_values:
/**
* {@inheritdoc}
*/
public function invoke($module, $hook, array $args = []) {
if (!$this->hasImplementations($hook, $module)) {
return;
}
$hookInvoker = \Closure::fromCallable($module . '_' . $hook);
return call_user_func_array($hookInvoker, $args);
}
/**
* {@inheritdoc}
*/
public function invokeAll($hook, array $args = []) {
$return = [];
$this->invokeAllWith($hook, function (callable $hook, string $module) use ($args, &$return) {
$result = call_user_func_array($hook, $args);
if (isset($result) && is_array($result)) {
$return = NestedArray::mergeDeep($return, $result);
}
elseif (isset($result)) {
$return[] = $result;
}
});
return $return;
}
Hence I get:
Error: Unknown named parameter $message in call_user_func_array() (line 427 of core/lib/Drupal/Core/Extension/ModuleHandler.php).
Proposed resolution
Use array_values so that in php 8.x the $args's keys aren't used for named properties:
/**
* {@inheritdoc}
*/
public function invoke($module, $hook, array $args = []) {
if (!$this->hasImplementations($hook, $module)) {
return;
}
$hookInvoker = \Closure::fromCallable($module . '_' . $hook);
return call_user_func_array($hookInvoker, array_values($args));
}
/**
* {@inheritdoc}
*/
public function invokeAll($hook, array $args = []) {
$return = [];
$this->invokeAllWith($hook, function (callable $hook, string $module) use ($args, &$return) {
$result = call_user_func_array($hook, array_values($args));
if (isset($result) && is_array($result)) {
$return = NestedArray::mergeDeep($return, $result);
}
elseif (isset($result)) {
$return[] = $result;
}
});
return $return;
}
Remaining tasks
Test case
Code review
Testing