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
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | 3310431-9.patch | 1.8 KB | prem suthar |
Issue fork drupal-3310431
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
wim leersThanks for trying this, and for the bug report!
Two questions:
Thanks! 🤓😊
Comment #3
longwaveWhich hook was being invoked, and was it core, contrib or custom code that invoked it? Can you post an extract of the caller?
Comment #4
defcon0 commentedSorry guys for the delay, I‘m on DrupalCon in Prague right now. Will answer on friday :-)
Comment #5
defcon0 commentedOK, now the promised feedback ;-)
Comment #6
defcon0 commentedSince the ticket is now in state "Postponed (maintainer needs more info)": what extra info is needed exactly?
Comment #7
defcon0 commentedChanging the status because no answer which additional info is needed has been provided. In my opinion all necessary info is given and the issue is not minor for php8 systems.
Comment #8
longwaveGiven that over in #3174022: call_user_func_array() and named arguments in PHP 8 we decided that named arguments were not supported in hook invocations, I think that it is probably OK to make the same change in ModuleHandler.
Setting to "Active" as there is no patch to review. If you want to make the suggested change and upload it, please then set the status to "Needs review".
Comment #9
prem suthar commentedUpload the Patch.
Comment #10
prem suthar commentedComment #12
smustgrave commentedThis issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.
Lowering as critical seems to be everyones sites are broken.
As a bug this will need a test case to show the issue.
Updated IS.
Comment #16
sahana _n commentedHi,
I tested the MR patch in Drupal 10.4 Please review.
If I missed anything, please let me know. I would greatly appreciate any guidance.
Thank you!!
Comment #17
smustgrave commentedMRs should be against 11.x
Also mentioned needing tests to show this is an issue.
Comment #18
nicxvan commentedComment #20
nicxvan commentedDo we still need to do this?