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)) {

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Manikandan Era created an issue. See original summary.

manikandan era’s picture

StatusFileSize
new1.03 KB
attheshow’s picture

Status: Active » Reviewed & tested by the community

Looks good. Thanks for sharing the patch.

graber’s picture

Status: Reviewed & tested by the community » Needs work

We need global namespace indicator on all functions and not some only.

if (is_array($value) && \array_key_exists('date', $value)) { -> if (\is_array($value) && \array_key_exists('date', $value)) {

etc.

bharath-kondeti made their first commit to this issue’s fork.

bharath-kondeti’s picture

Status: Needs work » Needs review

Addressed #4 and raised an MR. Please review

graber’s picture

Status: Needs review » Fixed

Thank you!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.