Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 293458

CKEditorPluginManager::getEnabledButtons throws warnings on PHP 8.0.0 beta3

$
0
0

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


Viewing all articles
Browse latest Browse all 293458

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>