Fatal error: Cannot unset string offsets in sites\all\modules\date\date_elements.inc on line 301.

Looks similar to #382722: Fatal error: Cannot unset string offsets in ...../public_html/sites/all/modules/date/date/date_elements.inc on line 288 and #299925: Fatal error: cannot unset string offsets however date_popup is enabled.

The error happens when end date is being cleared out because it is the same as the start date.

Looks like there is quite a history with this kind of error in the date module.

I will be proposing a fix similar to #2130575: unset() should be used with more caution in views_filter_handler_simple.inc.

CommentFileSizeAuthor
#1 date-unset-end-date-2503315-1.patch745 bytesCptCasual
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

CptCasual’s picture

Check for is_array and isset instead of !empty.

CptCasual’s picture

Status: Active » Needs review
spotzero’s picture

Status: Needs review » Reviewed & tested by the community

It bug comes from the fact that if $element['#default_value'] is a string, !empty($element['#default_value'][$to_field]) will return FALSE, and thus pass (and then running unset on $element['#default_value'][$to_field] when $element['#default_value'] is a string will cause a fatal error.)

This patch fixes the fatal error.

  • cafuego committed 489ed16 on 7.x-2.x authored by CptCasual
    Issue #2503315 by CptCasual: Fatal error: Cannot unset string offsets in...
cafuego’s picture

Version: 7.x-2.8 » 7.x-2.x-dev
Assigned: CptCasual » Unassigned
Status: Reviewed & tested by the community » Fixed

Merged with a small change.

I changed the isset() back to !empty() as in the original code. These two calls are not functionaly equivalent (specifically in how they handle a variable containing NULL).

Status: Fixed » Closed (fixed)

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