I was investigating an issue that looked like the following:
We have an embedded view within a panel pane that has views filters the user can modify within the pane configurations form. Upon submit/saving the panel pane, we get the following error:
Fatal error: Cannot create references to/from string offsets nor overloaded objects in ... /includes/common.inc on line 6696
I first found this issue:
But then realized that the way we are passing data to the view might be incorrect (since it's expecting an array and we are, instead, passing a string). Please consider the patch I will be posting in the comments below, but let me know if I am going about this the wrong way.
Thanks!
pcho
Comment | File | Size | Author |
---|---|---|---|
#14 | date-cannot_create_references_to_from_string_offsets-2449261-14.patch | 2.71 KB | daniel_j |
|
Comments
Comment #1
pcho CreditAttribution: pcho commentedPatch attached
Comment #2
SkyNet Costa Rica CreditAttribution: SkyNet Costa Rica as a volunteer commentedFatal error: Cannot create references to/from string offsets nor overloaded objects in ..../includes/common.inc on line 6726
Hello
I did apply the patch in Drupal 7.41, but I'm still getting the same error above.
do you have any idea of what I am getting the same error again.
Thanks
Comment #3
SocialNicheGuru CreditAttribution: SocialNicheGuru commentedComment #4
David Hernández CreditAttribution: David Hernández at Gizra commentedI've applied the patch and it correctly solved the issue.
Comment #5
David Hernández CreditAttribution: David Hernández at Gizra commentedI can provide a little more information about the issue. I've also solved it with a workaround implementing the next hook_form_alter:
The error comes from somewhere where the input is assigned an empty string instead of a FALSE. This causes this if to be used:
Found here: https://cgit.drupalcode.org/date/tree/date_api/date_api_elements.inc#n449
And as the $return variable is overridden there, this causes the next code to try to use a string as an array, generating the reported error:
Found here: https://cgit.drupalcode.org/date/tree/date_api/date_api_elements.inc#n465
Comment #6
daniel_j CreditAttribution: daniel_j commentedThe above patch is part of the solution to this problem, but it goes deeper. This issue is still happening after I apply the patch, and I think I've tracked down where it is occurring. In views/includes/view.inc, in view::get_exposed_input(), we see this snippet:
$this->exposed_input is then directly assigned to $form_state['input'] in the form constructor for views_exposed_form (this is done so that GET requests force Drupal to process form submission). (See views.module, views_exposed_form() function.)
When parsing a form element's input, Drupal assumes that the input structure matches the structure defined in the form element (i.e. assumes it got an array where an array was expected, or a scalar where a scalar was expected). When an array (or nested array) is expected, and a scalar (or an insufficiently-nested array) is received, Drupal chokes, and in the case of PHP 7.1, dies in a most undignified fashion.
Example: Let's say I have a view with an exposed date filter whose URL is as follows:
http://example.com/myview?field_date[value][year]=2018
But if I manually change the URL as follows, I generate a fatal error, at least under PHP 7.1:
http://example.com/myview?field_date[value]=2018
This is because Drupal expected $form_state['input']['field_date']['value'] to be an array, and it is in fact a scalar.
In the view::get_exposed_intput() method, views need some way of comparing the incoming data structure with the form's expected data structure, and either massaging it into shape or discarding it. Possibly this could be done via callbacks or hooks? Anyway, I don't think this is directly the fault of the date_views module; it's just that this is the most prominent contrib module that exposes form input data as an array.
My guess is that any resolution to this issue will require the views team and the date team to be working in tandem.
Comment #7
daniel_j CreditAttribution: daniel_j commentedThis patch prevents the fatal error on views exposed filter forms by detecting when the expected input should be an array but the actual input is a scalar. This is by no means ready for production, but I thought this could be the start of a proper discussion how to handle this within the date module (and its submodules) without having to get the Views team involved.
This patch probably works optimally in conjunction with the patch from issue 2889759.
Comment #8
daniel_j CreditAttribution: daniel_j commentedThis patch catches more cases that generated fatal errors.
Comment #9
joseph.olstadupdate title because too many titles similar to original title.
Comment #10
joseph.olstadFunction create_function() is deprecated in php 7.2
Comment #11
joseph.olstadactually, that function create_function probably not related to the patch.
Comment #12
collinhaines CreditAttribution: collinhaines commented#8 worked for me.
Comment #13
vinmassaro CreditAttribution: vinmassaro commented#8 works well, thank you!
Comment #14
daniel_j CreditAttribution: daniel_j commentedAccording to this PHP RFC,
uniqid()
may be deprecated in future versions of PHP, so I have re-rolled the patch from #8 to eliminate it.Comment #15
DamienMcKennaI reviewed the differences between the two patches, and while an interdiff would have been appreciated, the difference is negligible.
Comment #17
DamienMcKennaCommitted. Thank you.
Comment #19
klausiThis broke the Search API Views integration with a fatal error, patch in #3132404: Support Date module version 2.11-beta3.
Comment #20
joseph.olstadThe approach in number 5 might be better?
Comment #21
klausiHm, but this has now been released (although just as beta), so I think we cannot change this to not break existing sites that rely on it. Should we still do the approach in #5? Probably best if you create a new issue and describe what the remaining fix should be and why.