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
Comment #2
ladybug_3777 commentedPatch 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.......
Comment #3
mustanggb commentedI'm not sure if this is the best approach.
AFAIK you would only get this if
$returnwasn'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$inputis an empty string, rather than an array, before the first date is selected.Untested, but perhaps it might be better to do something like:
Comment #4
ladybug_3777 commentedYour 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!
Comment #5
jurgenhaasI have tested this patch and it solves that problem for me just perfectly.
Comment #6
jyraya commentedHello,
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.
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?
Comment #7
bramvandenbulcke commented@jyraya, if I remember correctly, these errors only occur on PHP 7.1 and higher.
Comment #8
jyraya commentedThanks for the information, @bramvandenbulcke.
Comment #9
bramvandenbulcke commentedMaybe 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.
Comment #10
jyraya commentedOk.
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.
Comment #11
akolahi commentedSeems like even with the #4 patch there is still an issue with PHP 7.1:
As the original post states:
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
Comment #12
akolahi commentedA bit more research. Might be related to this issue: https://www.drupal.org/project/drupal/issues/2313517
Comment #13
joseph.olstadThe 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.
Comment #14
akolahi commented@josepholstad Alright. Will do. https://www.drupal.org/project/date/issues/2961859
Comment #15
daniel_j commentedThe 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]=2018But if someone manually changes the URL to this:
example.com/myview?field_released_date_value[value]=2018I get the same warning + fatal error reported in #6.
Comment #16
joseph.olstadfor php 7.1 , please see related issue
#2961859: PHP 7.1 Exposed Date Field Issue WSOD Fatal Error: Cannot create references to/from string offsets
lets get 7.0 working first, meanwhile work on 7.1 can continue in #2961859: PHP 7.1 Exposed Date Field Issue WSOD Fatal Error: Cannot create references to/from string offsets
Comment #17
damienmckennaThis is an excellent fix, thank you. We'll add it to the next release.
Comment #18
joseph.olstadComment #19
joseph.olstadComment #21
damienmckennaCommitted! Thank you all for your help.
Comment #23
stevecory commentedWhen 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).
Comment #24
damienmckenna@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.
Comment #25
damienmckenna