Exposed filters causes Deprecated function: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated

Created on 4 April 2023, over 1 year ago
Updated 18 April 2024, 7 months ago

Problem/Motivation

Using exposed filters that rely on strpos() result in log warnings.

Deprecated function: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in Drupal\views_json_source\Plugin\views\query\ViewsJsonQuery->Drupal\views_json_source\Plugin\views\query\{closure}() (line 309 of /code/web/modules/contrib/views_json_source/src/Plugin/views/query/ViewsJsonQuery.php)

Steps to reproduce

Drupal 9.5.7; PHP 8.1.14; Create a view. Add multiple exposed filters using the "contains" operator. Leave at least one of the exposted filters empty on the form and submit. The dblog contains many warnings about passing null in the ops() function, which is line #300 in ViewsJsonQuery.php

I think it has to do with stripos() no longer allowing null as a parameter.

Proposed resolution

For each element in function ops(), check for null in $l and $r

The error went away for me when I added the check for !is_nul() like this:

'contains' => function ($l, $r) {
     if ((!is_null($l) and (!is_null(r))))  {
         return stripos($l, $r) !== FALSE;
     }

I'm not really sure the best way to do this, but I think it has to be checked for each element in the ops() function.

🐛 Bug report
Status

Closed: duplicate

Version

1.4

Component

Code

Created by

🇺🇸United States PaEricksonWaTech

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024