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:
- Install and enable the date_filter module in your Drupal installation.
- Create a new View or edit an existing View.
- Add a filter to the View and select the Date filter type from the list.
- 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.
- Save the View and visit the page where the View is displayed.
- Use the exposed filter to filter the results by date.
- 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.
- 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)) {
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | date_filter-3353672.patch | 1.03 KB | manikandan era |
| issue-1.png | 53.11 KB | manikandan era |
Issue fork date_filter-3353672
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
Comment #2
manikandan era commentedComment #3
attheshow commentedLooks good. Thanks for sharing the patch.
Comment #4
graber commentedWe 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.
Comment #7
bharath-kondeti commentedAddressed #4 and raised an MR. Please review
Comment #9
graber commentedThank you!