TypeError: Illegal offset type in isset or empty

Created on 7 June 2024, 4 months ago

Problem/Motivation

An error started appearing at odd moments, apparently after updating to php8

TypeError: Illegal offset type in isset or empty in FeedImport::getEntityInfo() (line 120 of /.../sites/all/modules/feed_import/feed_import_base/inc/feed_import.inc)

https://git.drupalcode.org/project/feed_import/-/blob/7.x-3.x/feed_impor...

The code there tries to do this

if (!isset($info->fields[$pval])) {
            $info->properties[] = $pval;
}

while it seems clears to the code right above it that $pval is likely an array.

Steps to reproduce

Update php8 and somehow invoke that method. I don't know why it got invoked at all.

Proposed resolution

if (is_scalar($pval) && !isset($info->fields[$pval])) {

To be honest, the code seems weird to me ?

Before php8, this would have thrown a warning,
but it has changed to an error

https://www.php.net/manual/en/migration80.incompatible.php
> A number of warnings have been converted into Error exceptions:
>
> * Attempting to use an invalid type (array or object) as an array key or string
> offset.

🐛 Bug report
Status

Active

Version

3.4

Component

Code

Created by

🇳🇱Netherlands commonpike

Live updates comments and jobs are added and updated live.
  • PHP 8.0

    The issue particularly affects sites running on PHP version 8.0.0 or later.

Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024