[wp-trac] [WordPress Trac] #57469: 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
Mon Jan 23 20:29:41 UTC 2023
#57469: Uncaught Error: array_merge(): Argument #3 must be of type array, null
given in wp-includes/widgets.php on line 1342
-------------------------------------------------+---------------------
Reporter: kesselb | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone:
Component: Widgets | Version:
Severity: normal | Resolution:
Keywords: php8 has-patch has-unit-tests close | Focuses:
-------------------------------------------------+---------------------
Comment (by kesselb):
Hi,
> If anything, a _doing_it_wrong should be thrown when receiving invalid
data (as is the case with your use-case).
Sounds good ;)
{{{#!php
<?php
function check_sidebars_widgets_for_invalid_values($value)
{
if (is_array($value)) {
$value = array_filter($value, static function ($var) {
return $var !== null;
});
}
return $value;
}
/**
* Upgrade to PHP 8 fails on some pages with an uncaught error:
*
* array_merge(): Argument #3 must be of type array, null given in wp-
includes/widgets.php on line 1342
*
* Starting with PHP 8 array_merge is stricter about null values.
* This filter will remove sidebars with null as value.
*/
add_filter('option_sidebars_widgets',
'check_sidebars_widgets_for_invalid_values', 1, 1);
}}}
If anyone has a similar issue. The above filter prevent the fatal error.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/57469#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list