I have a view that uses the following:

  • Exposed Date Filter for Month/Year
  • Table format
  • Clickable / Sortable Table Columns

When I upgraded to php 7 the view throws the following errors if I leave the exposed date filter BLANK (don't make a selection) and I click on a column to try and sort the view.

Warning: Illegal string offset 'month' in date_select_element_value_callback() (line 467 of /var/www/html/sites/all/modules/contrib/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 /var/www/html/sites/all/modules/contrib/date/date_api/date_api_elements.inc).
Warning: Illegal string offset 'year' in date_select_element_value_callback() (line 467 of /var/www/html/sites/all/modules/contrib/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 /var/www/html/sites/all/modules/contrib/date/date_api/date_api_elements.inc).

I believe this is due to the way arrays are handled with PHP 7. I will attach the patch created to address this item. I'm not sure if this is the best way to handle the issue, but if someone could review the patch that would be great!

Patching coming up....

Comments

ladybug_3777 created an issue. See original summary.

ladybug_3777’s picture

StatusFileSize
new630 bytes

Patch is attached. If a date is selected it will return the same way it already was. If not, it will return an empty array instead of setting the $formats[$field] to be an empty string. PHP7 didn't seem to want to have an empty string as it's value.

Review of this is appreciated. It's working for me but I may not be looking at the whole picture where this code may be called from other places and have a negative impact.......

mustanggb’s picture

I'm not sure if this is the best approach.

AFAIK you would only get this if $return wasn't an array, and it looks like the only way for that to happen is from the $return = $input; line. I'm guessing at some point $input is an empty string, rather than an array, before the first date is selected.

Untested, but perhaps it might be better to do something like:

-  if ($input !== FALSE) {
+  if ($input !== FALSE && is_array($input)) {
     $return = $input;
     $date = date_select_input_date($element, $input);
   }
ladybug_3777’s picture

StatusFileSize
new483 bytes

Your suggestion sounds reasonable and it worked when I gave it a try. Here's an official patch file for that change if other's would like to test it out as well. Thanks!

jurgenhaas’s picture

Status: Active » Reviewed & tested by the community

I have tested this patch and it solves that problem for me just perfectly.

jyraya’s picture

Hello,

I cannot reproduce this bug. I tested with 7.0.10 and the version 7.x-2.10, and I created the same kind of views described in the issue and I never got the error message.

Did I miss something?

Nevertheless, I noticed errors when I tested the views with the preview at the bottom of the "Views" definition interface but the messages are different.
In this case, the preview AJAX call returned an 500 HTTP error with a warning and a error message when I selected a month and year and used a table column filter.

Warning: Illegal string offset 'month' in drupal_array_set_nested_value() (line 6779 of /Applications/MAMP/htdocs/drupal/includes/common.inc).
Error: Cannot create references to/from string offsets nor overloaded objects in drupal_array_set_nested_value() (line 6779 of /Applications/MAMP/htdocs/drupal/includes/common.inc).

I also saw that in this case, the callback received a date value under the string format instead of the array format; e.g.: 2017-03. Should we not try to parse this value?

bramvandenbulcke’s picture

@jyraya, if I remember correctly, these errors only occur on PHP 7.1 and higher.

jyraya’s picture

Thanks for the information, @bramvandenbulcke.

bramvandenbulcke’s picture

Maybe I'm confused with the other issue: https://www.drupal.org/project/date/issues/2843367.

I know I can't go higher than the latest PHP 7.0 version because of that issue on a project of mine.

jyraya’s picture

Ok.

In the meantime, I tested the #4 patch in PHP 5.6, 7.0 and 7.1. It works in the 3 cases; no regression.

akolahi’s picture

Seems like even with the #4 patch there is still an issue with PHP 7.1:

As the original post states:

  • Exposed Date Filter for Month/Year
  • Table format
  • Clickable / Sortable Table Columns

Do not apply any filters. If you sort by any field: Cannot create references to/from string offsets in drupal_array_set_nested_value()

If you first apply a filter, then sort: No issues.

Looking closer at the URL.
Sorting without filtering first looks like this:field_date_value[value]
If you filter first (and it works): field_date_value[value][month]=2&field_date_value[value][year]=2017

Does not seem to be an issue with PHP 7.0. but only 7.1

akolahi’s picture

A bit more research. Might be related to this issue: https://www.drupal.org/project/drupal/issues/2313517

joseph.olstad’s picture

The latest patch above should be committed as-is and a release published in a new release of the date module version 2.11.
However for php 7.1 , open a new issue and add a link reference here.

akolahi’s picture

daniel_j’s picture

The patch in #4 does not resolve all the issues in play here. Strictly speaking, it resolves things where the end user is playing nice, but not when the end user plays with the URL's query string.

I am running on PHP 7.1, and I have a view with an exposed date filter which is filtering on year component only. Let's call the underlying field field_released_date. As expected, when someone alters the exposed filter value, it sends this query string:

example.com/myview?field_released_date_value[value][year]=2018

But if someone manually changes the URL to this:

example.com/myview?field_released_date_value[value]=2018

I get the same warning + fatal error reported in #6.

damienmckenna’s picture

This is an excellent fix, thank you. We'll add it to the next release.

damienmckenna’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: -php7 +PHP 7.0 (duplicate), +PHP 7.1

Committed! Thank you all for your help.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

stevecory’s picture

Version: 7.x-2.x-dev » 7.x-2.10
Issue tags: +PHP 7.2.16

When a column in a table is selected for sorting from a view the system responds with
Warning: Illegal string offset 'month' in date_select_element_value_callback() (line 467 of /home/www/html//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//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//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//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//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//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/atn/includes/common.inc).
Error: Cannot create references to/from string offsets in drupal_array_set_nested_value() (line 6794 of /home/www/html/atn/includes/common.inc).

I can get the date_api_elements.inc warnings to be removed applying ladybug_3777's patches #2 & #4, but it still shows

Warning: Illegal string offset 'month' in drupal_array_set_nested_value() (line 6779 of /Applications/MAMP/htdocs/drupal/includes/common.inc).
Error: Cannot create references to/from string offsets nor overloaded objects in drupal_array_set_nested_value() (line 6779 of /Applications/MAMP/htdocs/drupal/includes/common.inc).

damienmckenna’s picture

Version: 7.x-2.10 » 7.x-2.x-dev

@stevecory: This issue was fixed a while ago, it sounds like you need to test the current dev snapshot and if the problem still exists look for another issue or create a new one.

damienmckenna’s picture