I just upgraded to the recent version of date 5.x-2.x-dev and got the following error.

Cannot use object of type stdClass as array in /www-disk/home/comm/www/sites/all/modules/date/date_api.module

I was unable to figure out what was causing this. Does anyone have any suggestions. The only way I could fix it was to restore the older version of Date 5.x-2.x-dev. Hurray for back-ups.

Comments

karens’s picture

Status: Active » Fixed

I don't see any such error in the latest -dev and without more information on exactly what you were doing and where you saw it there is nothing I can do with this. Plus you left off the most important part of the error message which would have told me what line in the code the error occurred at.

Assuming since fixed because there have been lots more changes since this was reported.

cybermache’s picture

Status: Active » Fixed

Hi Karen,
Sorry for the vague posting, I must have been really frazzled that day. I just upgrading to Calendar 5.x-2.x-dev (2009-Mar-27) and Date 5.x-2.x-dev (2009-Mar-27) again to see if the latest changes have corrected this error. Going to my calendar page I get the following error on a white screen.

Fatal error: Cannot use object of type stdClass as array in /sites/all/modules/date/date_api.module on line 1445

I have four iCal calendars linked to this page and nothing else. I'm running Drupal 5.16 wih PHP 5.2.
I'm also getting this error on my recent log entries.

Object of class stdClass could not be converted to string in /sites/all/modules/date/date_api.module on line 1442.

Could this be due to my configurations somehow, since it's occurring in the date_format_order function? Let me know if you need more information. Oh, and if I don't have any ical calendars linked, the error message doesn't occur. That may be obvious but just in case.

Thanks for any help on this.

cybermache’s picture

Status: Fixed » Active
cybermache’s picture

Status: Fixed » Active

I've updated to Date 5.x 2.6 and the problem still persists.

Fatal error: Cannot use object of type stdClass as array in /sites/all/modules/date/date_api.module on line 1445

Looking at other posts with similar problems with other modules I noticed a pattern.

// using just examples here
$variable = $data['value'];
// Which they seem to always change to 
$variable = $data->value;
@1441 /sites/all/modules/date/date_api.module

function date_format_order($format) {
  $max = strlen($format);
  $order = array();
  for ($i = 0; $i <= $max; $i++) {
    $c = $format[$i]; // line 1445
    switch ($c) {
      case 'd':
      case 'j':
        $order[] = 'day';
        break;
      case 'F':
      case 'M':
      case 'm':
      case 'n':
        $order[] = 'month';
        break;
      case 'Y':
      case 'y':
        $order[] = 'year';
        break;
      case 'g':
      case 'G':
      case 'h':
      case 'H':
        $order[] = 'hour';
        break;
      case 'i':
        $order[] = 'minute';
        break;
      case 's':
        $order[] = 'second';
        break;
    }
  }
  return $order;
}

if I change lin 1445

-  $c = $format[$i];
+  $c = $format->$i;

I get this error

Fatal error: Cannot use string offset as an array in /sites/all/modules/date/date/date.theme on line 332

switching 332 from

-   $increment = $field['widget']['increment'];
+   $increment = $field->widget['increment'];

Allows the calendar to appear. This probably isn't even close to being a fix but it does stop the fatal errors.

nrasmus’s picture

Version: 5.x-2.x-dev » 5.x-2.6

subscribing--I too have this exact issue with 5.x.2.6.

nrasmus’s picture

Version: 5.x-2.6 » 5.x-2.x-dev

Sorry--my mistake--I was not on the latest version of calendar--latest dev of 5.x-2 for Date and Calendar fixed everything.

karens’s picture

Status: Active » Postponed (maintainer needs more info)

There's nothing I can do with this report without some information about what exactly you were doing and what kind of date field you're using and exactly how it's set up. I have to have enough information to replicate what you're seeing on my setup, without that I can't do anything.

But I suspect you're not really using the latest code anyway since the line numbers you mention in the latest code look nothing like the code above.

cybermache’s picture

Version: 5.x-2.x-dev » 5.x-2.7

This seems like a tricky one to explain. I've updated to date and calendar 2.7. I have a calendar imported using feed api that wasn't working right before but now is. I have to have two datestamp fields for the start and end of each event though to make it work. That's another issue altogether. So after I to link to an iCal calendar using the iCal feature in Calendar Setup I get the following error when navigating to the calendar page.

Fatal error: Cannot use object of type stdClass as array in .../sites/all/modules/date/date_api.module on line 1455

Removing the linked iCal causes this error to go away. Could this be a conflict with the feed module? The Calendar iCal feature doesn't use any Date CCk fields does it? Let me know what other info you need to assist in your replication.

Thanks

cybermache’s picture

Version: 5.x-2.7 » 5.x-2.x-dev
Status: Postponed (maintainer needs more info) » Active

Hey Karen,

Still having this error show up. I recently upgraded to Calendar 5.x-2.x-dev (2009-May-06) and Date 5.x-2.x-dev (2009-May-06) and received the same error (in drupals error log) when trying to view my calendar.view. I cleared the views cache and saved the date fields again I also cleared my browser cache just in case. I checked the iCal setup in the calendar settings page and that all checked out. I went ahead and changed those two lines again that I had mentioned above.

date_api.module @ line 1467
-    $c = $format[$i];
+   $c = $format->$i;

&
date.theme @ line 333
-  $increment = $field['widget']['increment'];
+  $increment = $field->widget['increment'];

This again stopped the error messages and displayed my calendar view with all my linked iCal calendars showing up except for the DTSTART & DTEND information. Again this isn't a feed and I am not mapping any of the iCal values to my CCK fields. I am simply using the iCal feature within the Calendar Setup page to display externally published iCal calendars.

If you still can not recreate this error perhaps you might have a suggestion for other places I could be looking for the cause of this problem? Perhaps another module is some how effecting this new version? If it would help I could list all the modules I have currently active.

Thanks

cybermache’s picture

Status: Active » Fixed

Well sometimes taking a break and then returning to a problem can be all you need to do. Upon revisiting this issue I remembered that I had done some custom theming for the calendar module. Doing a quick cross comparison I found that the element $field had been added to many of the functions that I had altered in my template file. Specifically theme_calendar_ical_field, theme_calendar_ical_node, and theme_calendar_date_combo. After adding '$field' to these and switching the date_api.module and date.theme back to their original state my calendars appeared just fine.

I'll leave this up, in case others find themselves making the same silly mistake.

Status: Fixed » Closed (fixed)

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