($haystack) must be of type array, null given bug

Created on 8 November 2022, over 1 year ago
Updated 24 April 2023, about 1 year ago

Problem/Motivation

In php 8, there is code in the .module file that results in possible nulls sent to inarray.

Steps to reproduce

VAPN installed in drupal 9.3 with php 8.1. Go to any page after install whilst not logged in, and the error message shows:

The website encountered an unexpected error. Please try again later.
TypeError: in_array(): Argument #2 ($haystack) must be of type array, null given in in_array() (line 113 of modules/contrib/vapn/vapn.module).

This error message goes away once the vapn has been configured to a particular type on the page /admin/config/vapn/vapnconfig

Proposed resolution

The line the error refers to is
if (empty($node->getType()) || !in_array($node->getType(),$configEnabled,TRUE)) {

The format of in_array is: in_array(mixed $needle, array $haystack, bool $strict = false)

Thus, haystack is $configEnabled is empty at the initial state of this install and should be checked within this line.

πŸ› Bug report
Status

Needs review

Version

1.5

Component

Code

Created by

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024