Problem/Motivation

Hello everyone, I came across this error when switching to php 8 the page returns an unexpected error:500, and in recent log messages print an error:

TypeError: Cannot access offset of type string on string in ctools_content_select_context() (line 812 of /ctools/includes/content.inc).

In code it preview like this:

    if (empty($conf['context'])) {
      $filtered = ctools_context_filter($contexts, $subtype_info['required context']);
      if ($filtered) {
        $keys = array_keys($filtered);
        $conf['context'] = array_shift($keys);//812 line
      }
    }

in this case it is worth checking for empty below on line 817

if (empty($conf['context'])) {
    return;
}

Proposed resolution

This is why you need to check $conf for an array:

if (is_array($conf) && empty($conf['context'])) {

Comments

Igumnov_aleksey created an issue. See original summary.

Igumnov_aleksey’s picture

Version: 7.x-1.19 » 7.x-1.9
Liam Morland’s picture

Issue tags: -PHP8 +PHP 8.0
Igumnov_aleksey’s picture

Issue summary: View changes
Igumnov_aleksey’s picture

joelpittet’s picture

Status: Needs review » Postponed (maintainer needs more info)

Please try a newer version of ctools as this issue may already be resolved.

Also, the error needs a stack trace because why is $conf a string, where is that variable being assigned a string value, that is likely the part that needs fixing, maybe custom code or another module?