TypeError: array_key_exists(): Argument #2 ($array) must be of type array, string given

Created on 5 September 2023, about 1 year ago
Updated 6 February 2024, 7 months ago

Problem/Motivation

Drupal 9.5.10, PHP 8.1

TypeError: array_key_exists(): Argument #2 ($array) must be of type array, string given in Drupal\date_filter\Plugin\views\filter\DateBase->acceptExposedInput() (line 315 of /var/www/web/modules/contrib/date_filter/src/Plugin/views/filter/DateBase.php)

Steps to reproduce

Assumes module is installed.

  1. Create a new View or edit an existing View.
  2. Add a filter to the View and select the Date field from the list.
  3. Check: Expose this filter to visitors, to allow them to change it
  4. Filter type to expose: choose Grouped filters
  5. Set Grouping 1 Operator to: Is Empty (NULL)
  6. Set Grouping 2 Operator to: Is Not Empty (NOT NULL)
  7. Save the View and visit page where view is displayed
  8. Use the grouped exposed filter configured and choose either Is Empty or Is Not Empty filter
  9. A WSOD will be returned caused by following error message: TypeError: array_key_exists(): Argument #2 ($array) must be of type array, string given in Drupal\date_filter\Plugin\views\filter\DateBase->acceptExposedInput() (line 315 of /var/www/web/modules/contrib/date_filter/src/Plugin/views/filter/DateBase.php)
  10. This seems to occur whenever not checking for an actual date value

Proposed resolution

The error indicates that the 2nd argument passed to the the array_key_exists() function is a string (empty or otherwise), which is not a valid argument since the function expects an array.

This follows on from https://www.drupal.org/project/date_filter/issues/3353672 🐛 TypeError: array_key_exists(): Argument #2 ($array) must be of type array, null given Fixed which resolves the array check on $value but not subsequent child arrays.

Therefore to resolve this, need to ensure that after \array_key_exists('value', $value), there is a check that $value['value'] is an array, before the \array_key_exists('date', $value['value']).

🐛 Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

🇫🇷France waako Normandie

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