Problem/Motivation

PHP 8 has added supported for named arguments. This can cause problems when using call_user_func_array() - see https://3v4l.org/YJbr3

Proposed resolution

Use array_values() where necessary.

Remaining tasks

User interface changes

None

API changes

None

Data model changes

None

Release notes snippet

N/a

CommentFileSizeAuthor
#12 3174022-12.patch1.95 KBandypost
#12 interdiff.txt556 bytesandypost
#2 3174022-2.patch1.88 KBalexpott

Comments

alexpott created an issue. See original summary.

alexpott’s picture

Status: Active » Needs review
Parent issue: » #3109885: [meta] Ensure compatibility of Drupal 9 with PHP 8.0 (as it evolves)
StatusFileSize
new1.88 KB

This one feels super tricky but here's what testing on core has revealed so far. Potentially anyone invoking a hook via the ModuleHandler::invoke* functions might trigger this.

Status: Needs review » Needs work

The last submitted patch, 2: 3174022-2.patch, failed testing. View results

andypost’s picture

Issue tags: +PHP 8.0
alexpott’s picture

Status: Needs work » Needs review
hussainweb’s picture

Status: Needs review » Reviewed & tested by the community

I came across this same issue in core or contrib (can't remember exactly where) and the fix was the same. This is again a change in PHP 8.0 behaviour.

hussainweb’s picture

I remember now. It was in this drush related project: https://github.com/consolidation/annotated-command/pull/210/files

andypost’s picture

Interesting, if phpstan can catch such cases, going to check if other places needs this fix

catch’s picture

+++ b/core/lib/Drupal/Core/Security/DoTrustedCallbackTrait.php
@@ -97,7 +97,7 @@ public function doTrustedCallback(callable $callback, array $args, $message, $er
 
-    return call_user_func_array($callback, $args);
+    return call_user_func_array($callback, array_values($args));
   }
 

Should we add comments to these cases explaining why the array_values() is necessary?

hussainweb’s picture

Should we add comments to these cases explaining why the array_values() is necessary?

I don't think it's very necessary to do that. This is going to be a PHP 8 effect and it shouldn't be too hard to check why is call_user_func_array with array_values a common pattern. But I'd go with the consensus here.

andypost’s picture

++ to 10, there's git history for that

andypost’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new556 bytes
new1.95 KB

Added todo and follow-up #3174150: Discuss use of named arguments in Renderer::doCallback()

It needs research pro/contra but at least this place now documented

hussainweb’s picture

Status: Needs review » Reviewed & tested by the community

Moving back to RTBC as the change is only a comment.

  • larowlan committed ba28c93 on 9.1.x
    Issue #3174022 by andypost, alexpott: call_user_func_array() and named...
larowlan’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: +Bug Smash Initiative

Committed ba28c93 and pushed to 9.1.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.