[wp-trac] [WordPress Trac] #57469: retrieve_widgets(): fatal error when a sidebar's widgets set to null (array is expected) (was: Uncaught Error: array_merge(): Argument #3 must be of type array, null given in wp-includes/widgets.php on line 1342)
WordPress Trac
noreply at wordpress.org
Tue Aug 8 14:32:08 UTC 2023
#57469: retrieve_widgets(): fatal error when a sidebar's widgets set to null (array
is expected)
--------------------------+---------------------
Reporter: kesselb | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone:
Component: Widgets | Version: 4.9
Severity: normal | Resolution:
Keywords: php80 close | Focuses:
--------------------------+---------------------
Changes (by hellofromTonya):
* keywords: php8 has-patch has-unit-tests close => php80 close
* version: => 4.9
Old description:
> When changing from PHP 7.4 to PHP 8.0 it's not possible to activate our
> theme.
>
> Fatal error: Uncaught Error: array_merge(): Argument #3 must be of type
> array, null given in wp-includes/widgets.php on line 1342
>
> {{{
> array_merge()
> wp-includes/widgets.php:1342
>
> retrieve_widgets()
> wp-includes/widgets.php:1287
>
> _wp_sidebars_changed()
> wp-includes/class-wp-hook.php:310
>
> WP_Hook::apply_filters()
> wp-includes/class-wp-hook.php:332
>
> WP_Hook::do_action()
> wp-includes/plugin.php:517
>
> do_action()
> wp-includes/theme.php:3395
>
> check_theme_switched()
> wp-includes/class-wp-hook.php:308
>
> WP_Hook::apply_filters()
> wp-includes/class-wp-hook.php:332
>
> WP_Hook::do_action()
> wp-includes/plugin.php:517
>
> do_action()
> wp-settings.php:617
>
> require_once()
> wp-config.php:103
>
> require_once()
> wp-load.php:50
>
> require_once()
> wp-admin/admin.php:34
>
> require_once()
> wp-admin/plugins.php:10
> }}}
>
> Line 1342:
> {{{#!php
> <?php
>
> $shown_widgets = array_merge( ...array_values( $sidebars_widgets ) );
> }}}
>
> $sidebars_widgets
>
> {{{
> array (
> 'wp_inactive_widgets' =>
> array (
> ),
> 'sidebar-standard' =>
> array (
> ),
> 'sidebar-marken' => NULL,
> 'sidebar-typen' => NULL,
> 'sidebar-test' => NULL,
> 'sidebar-zubehoer' => NULL,
> 'sidebar-ratgeber' => NULL,
> )
> }}}
>
> PHP 8.0+ throws a type error when a non-array value is given to
> array_merge.
>
> I guess NULL is not a valid value for the sidebar widgets.
> Maybe our theme wrote this weird state to the options field.
>
> Patch: https://github.com/WordPress/wordpress-develop/pull/3848
New description:
When changing from PHP 7.4 to PHP 8.0 it's not possible to activate our
theme.
{{{
Fatal error: Uncaught Error: array_merge(): Argument #3 must be of type
array, null given in wp-includes/widgets.php on line 1342
}}}
{{{
array_merge()
wp-includes/widgets.php:1342
retrieve_widgets()
wp-includes/widgets.php:1287
_wp_sidebars_changed()
wp-includes/class-wp-hook.php:310
WP_Hook::apply_filters()
wp-includes/class-wp-hook.php:332
WP_Hook::do_action()
wp-includes/plugin.php:517
do_action()
wp-includes/theme.php:3395
check_theme_switched()
wp-includes/class-wp-hook.php:308
WP_Hook::apply_filters()
wp-includes/class-wp-hook.php:332
WP_Hook::do_action()
wp-includes/plugin.php:517
do_action()
wp-settings.php:617
require_once()
wp-config.php:103
require_once()
wp-load.php:50
require_once()
wp-admin/admin.php:34
require_once()
wp-admin/plugins.php:10
}}}
Line 1342:
{{{#!php
<?php
$shown_widgets = array_merge( ...array_values( $sidebars_widgets ) );
}}}
$sidebars_widgets
{{{
array (
'wp_inactive_widgets' =>
array (
),
'sidebar-standard' =>
array (
),
'sidebar-marken' => NULL,
'sidebar-typen' => NULL,
'sidebar-test' => NULL,
'sidebar-zubehoer' => NULL,
'sidebar-ratgeber' => NULL,
)
}}}
PHP 8.0+ throws a type error when a non-array value is given to
array_merge.
I guess NULL is not a valid value for the sidebar widgets.
Maybe our theme wrote this weird state to the options field.
Patch: https://github.com/WordPress/wordpress-develop/pull/3848
--
Comment:
**Changes in the ticket:**
* Updated the Summary to better reflect the issue being reported, i.e. for
discoverability.
* Updated the Version to 4.9.
* Wrapped the PHP error in the Description.
* Reset the keywords as the PR was closed.
* Changed keyword to `php80` to identify which PHP version increased the
error's severity.
**Error across PHP versions:**
If `null` or a non-array is set for the widgets of a sidebar, then PHP
throws an error (see it in action https://3v4l.org/i45nZ):
* < 7.3: `Warning: array_merge(): Argument #3 is not an array `
* PHP 7.3 to 7.4: `Warning: array_merge(): Expected parameter 3 to be an
array, null given`
* PHP 8+: `Fatal error: Uncaught TypeError: array_merge(): Argument #3
must be of type array, null given`.
**Historical context:**
* [41555] / #39693 (during WP 4.9):
* Introduced `wp_map_sidebars_widgets()`.
* `retrieve_widgets()`:
* Invoked `wp_map_sidebars_widgets()` to map `$sidebars_widgets`
* Added `$shown_widgets = call_user_func_array( 'array_merge',
$sidebars_widgets );`.
* [48839] / #50913 (during WP 5.6):
* `retrieve_widgets()`: changed `call_user_func_array( 'array_merge',
$sidebars_widgets );` to `array_merge( ...array_values( $sidebars_widgets
) );`.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/57469#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list