Problem/Motivation

When manually testing a website on PHP 8 beta 3, I saw the log filled up with warnings from CKEditorPluginManager::getEnabledButtons from the array_reduce call. It can be seen in this snippet: https://3v4l.org/CUCvi . In case the 3v4l is no longer available, here is the snippet:


$arr = [1,2,3];
$reduced = array_reduce($arr, function (&$result, $items) { }, []);

It only reports warnings from PHP 8.0.0 alpha 2 onwards which means this worked fine on PHP 7.4 and even early versions of PHP 8.

The warning (in case of Drupal) is:

Warning: Drupal\ckeditor\CKEditorPluginManager::Drupal\ckeditor\{closure}(): Argument #1 ($result) must be passed by reference, value given in Drupal\ckeditor\CKEditorPluginManager::getEnabledButtons() (line 127 of /var/www/html/web/core/modules/ckeditor/src/CKEditorPluginManager.php)

#0 /var/www/html/web/core/includes/bootstrap.inc(308): _drupal_error_handler_real(2, 'Drupal\\ckeditor...', '/var/www/html/w...', 127, NULL)
#1 [internal function]: _drupal_error_handler(2, 'Drupal\\ckeditor...', '/var/www/html/w...', 127)
...

The problem is that in the callback for array_reduce, the first parameter is passed by reference. At the same time, the initial value passed to array_reduce is a literal [].

Steps to reproduce

Setup Drupal core 9.1.x on PHP 8 beta 3 and apply patches from #3156595: Make Drupal 9 installable on PHP8 and other issues to get Drupal installable and working. Go to /node/add/article. The node add page should load properly. Go to dblog to see it filled with warnings.

Proposed resolution

From reading the code, I'm not sure why the parameter in the callback should be a reference. The function body returns the modified array which should be passed back in the next iteration. We could just let it be passed as value.

Remaining tasks

Patch

User interface changes

None

API changes

None

Data model changes

None

Release notes snippet

N/A

CommentFileSizeAuthor
#2 3170648-2.patch804 byteshussainweb

Comments

hussainweb created an issue. See original summary.

hussainweb’s picture

Status: Active » Needs review
StatusFileSize
new804 bytes

Even though the Issue Summary is so long, the patch is just a single character change. :)

hussainweb’s picture

Issue summary: View changes

Fixing a small mistake in IS where I mention the problem is from PHP 8 beta 2. It's actually from PHP 8 alpha 2.

andypost’s picture

I guess it caused by change in php.ini to default to E_ALL cos I see no relation to in https://wiki.php.net/rfc/engine_warnings

alexpott’s picture

This looks good to me. I'd rtbc it but then I can not commit.

andypost’s picture

Status: Needs review » Reviewed & tested by the community

I missed 3v4l link in summary, it explains

Pretty straightforward patch, rtbc

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed 7a2d7e0494 to 9.1.x and 9bb004cd41 to 9.0.x and fd821085bc to 8.9.x. Thanks!

Backported this to 8.9.x as it looks risk free and will make PHP 8 compat in Drupal 8 possible.

  • alexpott committed 7a2d7e0 on 9.1.x
    Issue #3170648 by hussainweb: CKEditorPluginManager::getEnabledButtons...

  • alexpott committed 9bb004c on 9.0.x
    Issue #3170648 by hussainweb: CKEditorPluginManager::getEnabledButtons...

  • alexpott committed fd82108 on 8.9.x
    Issue #3170648 by hussainweb: CKEditorPluginManager::getEnabledButtons...

Status: Fixed » Closed (fixed)

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