Error: Cannot create references to/from string offsets in drupal_array_set_nested_value() (line 6794 of /home/www/html/<studyname>/includes/common.inc).

Created on 16 May 2019, over 5 years ago
Updated 4 July 2024, 7 months ago

The View contains:
Format: Table
Fields: (Title), (Date), (Category), (Type) and (File)
Filter Criteria Content: Published (Yes), Content: Type (Documents), Content: Date (Exposed Select Day)

Configure filter criterion: Content: Date (field_doc_date)
Appears in: node:Documents.
Expose this filter to visitors, to allow them to change it: CHECKED

Filter type to expose: Single filter: RADIO Selected
Operator: "Is Between"

________: Select a date > Month | Day | Year
Start date: Select a date > Month | Day | Year
End date: Enter a relative date > now +1 month

MORE
Administrative title:
Filter identifier > field_doc_date_value

Which does appear in the URL after the ? to identify this filter.

I feel that this error is due to the "Start Date" being empty upon the initial rendering.
After the initial rendering, the end user may select the "Date" column in order to sort the table without selecting a Start Date.

This causes the URL to send the request as: all?field_priv_doc_date_value[min]&field_priv_doc_date_value[max]&order=field_priv_doc_date&sort=asc

and following error is displayed:
Warning: Illegal string offset 'month' in date_select_element_value_callback() (line 467 of /home/www/html/precise/sites/all/modules/date/date_api/date_api_elements.inc).
Warning: Cannot assign an empty string to a string offset in date_select_element_value_callback() (line 467 of /home/www/html/precise/sites/all/modules/date/date_api/date_api_elements.inc).
Warning: Illegal string offset 'day' in date_select_element_value_callback() (line 467 of /home/www/html/precise/sites/all/modules/date/date_api/date_api_elements.inc).
Warning: Cannot assign an empty string to a string offset in date_select_element_value_callback() (line 467 of /home/www/html/precise/sites/all/modules/date/date_api/date_api_elements.inc).
Warning: Illegal string offset 'year' in date_select_element_value_callback() (line 467 of /home/www/html/precise/sites/all/modules/date/date_api/date_api_elements.inc).
Warning: Cannot assign an empty string to a string offset in date_select_element_value_callback() (line 467 of /home/www/html/precise/sites/all/modules/date/date_api/date_api_elements.inc).
Warning: Illegal string offset 'month' in drupal_array_set_nested_value() (line 6794 of /home/www/html/precise/includes/common.inc).
Error: Cannot create references to/from string offsets in drupal_array_set_nested_value() (line 6794 of /home/www/html/precise/includes/common.inc).

The function is looking for the [min][month], [min][day], [min][year], [max][month], [max][day] and [max][year].

If the Start Date is set to a value (e.g. 1/1/2019), it causes the URL to send the request as all?field_priv_doc_date_value[min][month]=1&field_priv_doc_date_value[min][day]=1&field_priv_doc_date_value[min][year]=2019&field_priv_doc_date_value[max][month]=6&field_priv_doc_date_value[max][day]=16&field_priv_doc_date_value[max][year]=2019

and then the error does not display.

πŸ› Bug report
Status

Active

Version

3.0

Component

exposed filters

Created by

πŸ‡ΊπŸ‡ΈUnited States stevecory

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.

  • This is a PHP error stating that you are trying to create a reference to a string offset, which is not allowed in PHP.
    The following function (includes/common.inc) caused the error:

    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;
    }

    you have to check if $ref is an array and if its initialized already (if not, the function should exit immediately)

    try this:

    function drupal_array_set_nested_value(array &$array, array $parents, $value, $force = FALSE) {
      $ref = &$array;
      foreach ($parents as $parent) {
        if (!isset($ref) || !is_array($ref)) {
          if ($force) {
            $ref = array();
          }
          else {
            return;
          }
        }
        $ref = &$ref[$parent];
      }
      $ref = $value;
    }

    it worked for me.

  • πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA
  • πŸ‡¦πŸ‡²Armenia alen simonyan

    Hi, I have created an issue https://www.drupal.org/project/drupal/issues/3458997 πŸ› TypeError: Cannot access offset of type string on string in drupal_array_set_nested_value() (line 6955 of /includes/common.inc). Active , because the search didn't show this one.

    I managed to fix this error with this patch.

Production build 0.71.5 2024