PHP Warning: in_array() expects parameter 2 to be array
-
I noticed this past week after upgrading to v. 3.3.0 of the dsIDXPress plugin that my error log was filling up with errors like the following:
PHP Warning: in_array() expects parameter 2 to be array, null given in /home/username/public_html/wp-content/plugins/dsidxpress/widget-idx-guided-search.php on line 109
PHP Warning: array_map(): Argument #2 should be an array in /home/username/public_html/wp-content/plugins/dsidxpress/widget-idx-guided-search.php on line 109I do have the premium version of the IDX Guided Search widget on the site, but try as I might, I haven’t been able to reproduce the warning. I’ve tried doing searches with no parameters, searches with different variations of cities selected, and even tried accessing the file directly, but I haven’t been able to figure out how users/bots are triggering the warning. However, if I wait a while, the error log starts filling up again. It actually got as high as 100 MB at one point, so it can definitely be an issue for users who have limited disk space.
The problem code is line 109 in /wp-content/plugins/dsidxpress/widget-idx-guided-search.php:
$selected = in_array(strtolower($city), array_map('strtolower', $values['idx-q-Cities']))?' selected="selected"':'';
I found a workaround that appears to retain the functioning of the widget but prevents the warnings by testing to be sure that
$values['idx-q-Cities']
is an array before using it in the in_array function. To try it, simply replace line 109 of /wp-content/plugins/dsidxpress/widget-idx-guided-search.php with the following:if (is_array($values['idx-q-Cities'])) { $selected = in_array(strtolower($city), array_map('strtolower', $values['idx-q-Cities']))?' selected="selected"':''; } else { $selected = ''; }
I don’t think it matters, but I’m using WP 5.0.2 on PHP 7.1.
- The topic ‘PHP Warning: in_array() expects parameter 2 to be array’ is closed to new replies.