Editing a node with an empty date field produces the following:

  • Warning: Illegal string offset 'value' in date_combo_element_process() (line 295 of /htdocs_20161220/sites/all/modules/date/date_elements.inc).
  • Warning: Cannot assign an empty string to a string offset in date_combo_element_process() (line 295 of /htdocs_20161220/sites/all/modules/date/date_elements.inc).
  • Warning: Illegal string offset 'value' in date_local_date() (line 145 of /htdocs_20161220/sites/all/modules/date/date_elements.inc).
  • Notice: Uninitialized string offset: 0 in date_local_date() (line 145 of /htdocs_20161220/sites/all/modules/date/date_elements.inc).
  • Warning: Illegal string offset 'value' in date_combo_element_process() (line 298 of /htdocs_20161220/sites/all/modules/date/date_elements.inc).
  • Warning: Cannot assign an empty string to a string offset in date_combo_element_process() (line 298 of /htdocs_20161220/sites/all/modules/date/date_elements.inc).
  • Warning: Illegal string offset 'value2' in date_combo_element_process() (line 295 of /htdocs_20161220/sites/all/modules/date/date_elements.inc).
  • Warning: Cannot assign an empty string to a string offset in date_combo_element_process() (line 295 of /htdocs_20161220/sites/all/modules/date/date_elements.inc).
  • Warning: Illegal string offset 'value2' in date_local_date() (line 145 of /htdocs_20161220/sites/all/modules/date/date_elements.inc).
  • Notice: Uninitialized string offset: 0 in date_local_date() (line 145 of /htdocs_20161220/sites/all/modules/date/date_elements.inc).
  • Warning: Illegal string offset 'value2' in date_combo_element_process() (line 298 of /htdocs_20161220/sites/all/modules/date/date_elements.inc).
  • Warning: Cannot assign an empty string to a string offset in date_combo_element_process() (line 298 of /htdocs_20161220/sites/all/modules/date/date_elements.inc).

Steps to reproduce:

  1. Add a date field to a content type.
  2. Create a new node of that type.
  3. Edit the newly created field.
Members fund testing for the Drupal project. Drupal Association Learn more

Comments

RemyAroundTown created an issue. See original summary.

RemyAroundTown’s picture

$element['#default_value'] can be an empty string but is used as a multi-level array. In previous versions of PHP this would not throw a warning.

The attached fix checks for an empty element that is not an array and assigns an empty array if required.

RemyAroundTown’s picture

Status: Active » Needs review
RemyAroundTown’s picture

And as soon as I queue the test I realize it won't pass in php 5.3 due to my use of []. Here's a more backwards compatible patch.

Status: Needs review » Needs work

The last submitted patch, 4: 2843367-php71-string-offset-2.patch, failed testing.

glynster’s picture

I can confirm this patch does resolve the issue for me using php7.1. I am not sure what needs to be adjusted to get this to pass. +1 from me regardless. RTBC

RemyAroundTown’s picture

Status: Needs work » Reviewed & tested by the community

It looks like the module itself is failing tests, so that might be another issue that should be cleared up. I'm going to bump the status of this one.

matthiasm11’s picture

Patch #4 looks fine, thanks.

oadaeh’s picture

Issue summary: View changes

I'm just making it a little easier to scan through the error notices in the summary.

johnzzon’s picture

Patch #4 working fine for me as well.

robertgarrigos’s picture

patch #4 worked for me also.

DamienMcKenna’s picture

Issue tags: -php7.1 +PHP 7.1

I've re-queued the tests, lets see how this does.

DamienMcKenna’s picture

DamienMcKenna’s picture

Assigned: RemyAroundTown » Unassigned
DamienMcKenna’s picture

So the tests still fail with 7.0 and 7.1, would someone care to look at them?

https://www.drupal.org/pift-ci-job/635955

https://www.drupal.org/pift-ci-job/635956

DamienMcKenna’s picture

I opened #2865376 so we can look into PHP 7 issues in general.

oadaeh’s picture

DamienMcKenna’s picture

Liam Morland’s picture

Liam Morland’s picture

Sorry, already linked.

alesr’s picture

I did some debugging and the tests are not failing because of this patch.

The problem is in getting the site content to assertText on.

For example: $this->drupalGet('admin/structure/types/manage/story/fields'); (line 78 in date_tools.test)
The content is empty when returned from CURL.

Running tests without the patch also returns the same fails.

alesr’s picture

I was still getting errors on some specific edit pages.
After a closer look I found out the condition set in patch (with &&) is wrong.

if (empty($element['#default_value']) && !is_array($element['#default_value'])) {...}

If '#default_value' index in $element['#default_value'] is not set, empty($element['#default_value']) with be true and it will go to the next check which is !is_array($element['#default_value']). In this check '#default_value' doesn't exist and will return a notice/error.

Here's a patch that fixes this.
The correct condition should be OR (||).

if (empty($element['#default_value']) || !is_array($element['#default_value'])) {...}

If default_value is empty/not set OR not an array...

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 22: 2843367-php71-string-offset-22.patch, failed testing. View results

alesr’s picture

Status: Needs work » Needs review

As mentioned in #21, the tests are failing even without any patch from this issue so that needs to be addressed outside this issue.
I will set it to "Needs review".

joelpittet’s picture

@alesr, #22 doesn't apply, the tests are showing that, you may not be creating against the 2.x-dev branch?

I'm re-uploading the RTBC'd #4

alesr’s picture

Majdi’s picture

Works for me

szeidler’s picture

Patch #26 is also fixing the issue for me on PHP 7.1. I'm not sure about the testbot, but when running the tests locally there is no difference between the number of passed and failed tests before and after applying the patch. So they seems to be unrelated to this particular issue.