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

Created on 12 April 2023, about 1 year ago
Updated 23 May 2023, about 1 year ago

Problem/Motivation

Drupal 9.5.3, PHP 8.1

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

Steps to reproduce

Install Module

Here are the steps to reproduce this error:

  1. Install and enable the date_filter module in your Drupal installation.
  2. Create a new View or edit an existing View.
  3. Add a filter to the View and select the Date filter type from the list.
  4. In the filter settings, select the Expose this filter to visitors, to allow them to change it checkbox to make the filter available to users.
  5. Save the View and visit the page where the View is displayed.
  6. Use the exposed filter to filter the results by date.
  7. The error message TypeError: array_key_exists(): Argument #2 ($array) must be of type array, null given in Drupal\date_filter\Plugin\views\filter\DateBase->acceptExposedInput() will be displayed on the page.
  8. This error occurs when the acceptExposedInput() method in the DateBase class receives an invalid argument, which is usually caused by incorrect configuration or input data. To resolve this error, you may need to review the filter settings and input data to ensure that they are valid and properly configured.

Proposed resolution

The error message indicates that the second argument passed to the array_key_exists() function is null, which is not a valid argument since the function expects an array.

To resolve this error, you need to ensure that the second argument passed to the array_key_exists() function is actually an array. You can do this by adding a check for the data type of the variable before using it in the array_key_exists() function.

This will ensure that the array_key_exists() function is only called when the second argument is an actual array, and will prevent the TypeError from being thrown.

if (is_array($my_array) && array_key_exists($my_key, $my_array)) {

๐Ÿ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

๐Ÿ‡ฎ๐Ÿ‡ณIndia Manikandan Era

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

Comments & Activities

Production build 0.69.0 2024