PHP 8 Fatal Error: array_diff() Argument #1 must be array
-
Hi,
We encountered a fatal error when saving settings in the plugin under PHP 8.x.
Error message:
Fatal error: Uncaught TypeError: array_diff(): Argument #1 ($array) must be of type array, false given in /wp-content/plugins/searchpro/inc/helper-functions.php on line 1592The issue occurs inside the function:
bwp_is_option_updated()Specifically this line:
return !empty(array_diff($option_val, $urls_array));In some cases
get_option($option_name)returnsfalse(likely when the option does not yet exist), which causesarray_diff()to throw a TypeError in PHP 8+.As a temporary fix, we changed the line to:
return !empty(array_diff(is_array($option_val) ? $option_val : [], $urls_array));This prevents the fatal error and ensures compatibility with PHP 8.
It may be worth updating the plugin to validate that
$option_valis always an array before callingarray_diff()to avoid breaking admin pages under newer PHP versions.Environment:
- WordPress: Latest
- PHP: 8.x
- Plugin version: 3.1.17
Hope this helps.
You must be logged in to reply to this topic.