TypeError: Cannot access offset of type string on string in drupal_array_set_nested_value() (line 6955 of /includes/common.inc).

Created on 4 July 2024, 7 months ago
Updated 11 July 2024, 6 months ago

Problem/Motivation

TypeError: Cannot access offset of type string on string in drupal_array_set_nested_value() (line 6955 of /includes/common.inc).
The website encountered an unexpected error. Please try again later.

Steps to reproduce

This error appeared after updating the Drupal version 7.101 and pages built by the views started to throw an error if you have filters on it.
This bug comes when calling drupal_array_set_nested_value from _form_builder_handle_input_element in /includes/form.inc file.

function _form_builder_handle_input_element($form_id, &$element, &$form_state) {
  ...
      if (!$input_exists && !$form_state['rebuild'] && !$form_state['programmed']) {
        // Add the necessary parent keys to $form_state['input'] and sets the
        // element's input value to NULL.
        drupal_array_set_nested_value($form_state['input'], $element['#parents'], NULL);
        $input_exists = TRUE;
      }
  ...
}
function drupal_array_set_nested_value(array &$array, array $parents, $value, $force = FALSE) {
  $ref = &$array;
  foreach ($parents as $parent) {
    // PHP auto-creates container arrays and NULL entries without error if $ref
    // is NULL, but throws an error if $ref is set, but not an array.
    if ($force && isset($ref) && !is_array($ref)) {
      $ref = array();
    }
    $ref = &$ref[$parent];
  }
  $ref = $value;
}

Proposed resolution

The function drupal_array_set_nested_value should be called with force = TRUE argument to match the statement
"when $ref is set, but not an array" in drupal_array_set_nested_value function.

πŸ› Bug report
Status

Active

Version

7.0 ⚰️

Component
Form  β†’

Last updated about 8 hours ago

Created by

πŸ‡¦πŸ‡²Armenia alen simonyan

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

Comments & Activities

Production build 0.71.5 2024