Make WordPress Core

#58351 closed defect (bug) (duplicate)

PHP Fatal error: Uncaught TypeError: array_merge()

Reported by: lenasterg's profile lenasterg Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Widgets Keywords: php80 needs-testing-info
Focuses: Cc:

Description

Hi all.
I have a multisite installation WordPress 6.2, PHP 8.1.
In some subsites, that after switched themes I get the following PHP Fatal error

PHP Fatal error: Uncaught TypeError: array_merge(): Argument #2 must be of type array, null given in /wp-includes/widgets.php:1342

This is caused when executing the line of code
$shown_widgets = array_merge( ...array_values( $sidebars_widgets ) );,
I guess that means that the $sidebars_widgets variable is either null or contains a null value instead of an array.

A fix for that is to add the following two lines

$sidebars_widgets = array_filter($sidebars_widgets);
if ( empty( $sidebars_widgets ) ) {
    return array();
}

before the line :
https://core.trac.wordpress.org/browser/trunk/src/wp-includes/widgets.php#L1342

Bests,
Lena

Change History (8)

#1 @spacedmonkey
13 months ago

  • Keywords php8 added

#2 @spacedmonkey
13 months ago

  • Keywords php81 added; php8 removed

#3 @jrf
12 months ago

  • Keywords php80 added; php81 removed

#4 @jrf
12 months ago

Thanks @lenasterg for reporting this.

While your proposal fixes the immediate issue, it doesn't address the actual issue, which is "how did that null value get in the $sidebar_widgets array ?"

I think this needs a little deeper investigation and backtracing to figure out what is really going on.

#5 @lenasterg
12 months ago

Hi @jrf.
I have no clue. It happened on in one subsite, which the user hadn't edited it for more than a year.
During this period, we updated the multisite installation from WP 4.9+ to 6.2.1.
The user can't remember the initial theme, his blog had.

This ticket was mentioned in Slack in #core-test by ironprogrammer. View the logs.


12 months ago

#7 @ironprogrammer
12 months ago

  • Keywords needs-testing-info added

During test triage review of this ticket, it was agreed that needs-testing-info might help move it forward. Why? This issue may be challenging to reproduce and validate a patch. Also, in the process, additional research and context into what caused the issue might be revealed, as suggested in comment:4.

#8 @hellofromTonya
10 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

The issue of a sidebar's widgets being set to null instead of array is being tracked in #57469. Let's move the discussion and investigation to that ticket to consolidate the effort. Thank you everyone!

Note: See TracTickets for help on using tickets.