I got this error message when I start to create a reservation (like event I guess).

warning: get_class() called without object from outside a class in ...sites/all/modules/date/date_api.module on line 710.

I can make the reservation anyway, but I couldn't see it on the calendar. Yet. I've just installed the module.

Comments

kyberman’s picture

Project: Event Bookings » Date
Version: 6.x-1.x-dev » 6.x-2.7

The same error, but it seems to be the Date module problem (I don't have installed Event Bookings module). The error shows after update to version 2.7, when node with Date CCK field is saved.

merilainen’s picture

Component: Code » Date API

Here is the whole error message:

warning: get_class() called without object from outside a class in .../sites/all/modules/date/date_api.module on line 710.

Seems to be related to Date API. But I'm not sure if the problem is there or in the Eventbookings module, because I don't get this problem with other content types. I think it's calling the Date API in wrong manner.

omerida’s picture

Status: Active » Needs review
StatusFileSize
new603 bytes

Seems to happen if $date is empty, which causes the function to return early. Reversing the tests gets rid of the notice. Attached is a patch.

kyberman’s picture

For me, the problem has gone after change in "date_api.module" (line 710) from:

if (get_class($date) != 'DateTime') {
  $date = date_make_date($date);
}
if (empty($date)) {
  return '';
}

to:

if (empty($date)) {
  return '';
}
if (get_class($date) != 'DateTime') {
  $date = date_make_date($date);
}

Is this correct, or wrong way?

EDIT: Now, I see that the patch from omerida do the same thing :-)

hnln’s picture

sub

karens’s picture

Status: Needs review » Needs work

This is a patch for an older version of the code. Everyone is referring to some code that no longer looks the same. Since this part of the code has changed, someone needs to see if there is still a problem in the latest dev version, and if so, provide a patch for that.

omerida’s picture

Version: 6.x-2.7 » 6.x-2.x-dev
Status: Needs work » Needs review
StatusFileSize
new641 bytes

The case for get_class being called still exists in the code for the dev snapshot. Attached is a patch to fix it.

rob c’s picture

#4 & #7 looking good, this seems to fix the problem for me in the 2.7 release.

arlinsandbulte’s picture

Status: Needs review » Fixed

fixed:
http://drupalcode.org/project/date.git/commit/58c3f6e

Note:
This change made sense and looked pretty simple, so I applied it without really verifying it fixes a problem.
In the future, please provide details on how the error message can be reproduced. Preferably, try reproducing the error on a clean Drupal install.

That way, module maintainers can:
1.) First reproduce the error
2.) apply the patch
3.) then verify that the patch eliminates the error.

I know this takes time and is not always possible. But doing so will CERTAINLY help your issue/patch get implemented.
AT THE VERY LEAST, you should at least mention that you TRIED to reproduce the problem.

The more detail you give, the faster we can react.

Status: Fixed » Closed (fixed)

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

bohz’s picture

Status: Closed (fixed) » Active

Sorry to reopen this.
I am experiencing a very similar error:
get_class() expects parameter 1 to be object, string given in /home/.../sites/all/modules/date/date_api.module on line 719.
This happens with both 6.x-2.8 and 6.x-2.x-dev when accessing the full node.
I have checked the above patch is in use in my version.
Dates are saved correctly, views and other modules work as expected.

[EDIT2] It seems this happens only when using Times; get_class($date) is actually empty This happens because when I use start and end dates, the start date is a string not an object; like: $date = '2012-04-25 00:00:00'
I have added this check

$date = (is_object($date) ? $date : date_make_date($date));

And the error went away but still, I would like to know what happens!

I am unsure if this is caused by my setup: (updated) default LAMP stack on Ubuntu 10.04 server with PEAR - PHP Extension enabled.

Any hint on how to (properly) solve this problem is welcome.

THanks!!

omerida’s picture

You should file a new ticket and leave this one closed/fixed.

boran’s picture

One year later (almost :-)
I had the exact same problem as #11 with v2.9 (the stable release at the time of writing).
I also have start/end dates.
The quick fix in #11 worked too, adding that line before line 719

uv516’s picture

Issue summary: View changes

One mere year later the error appear in the newest version (6.x-2.10).
#11 solve the problem, but du we have to do this at every update?

rukayya’s picture

StatusFileSize
new237 bytes

I resolved that error by applying the following patch

rukayya’s picture

StatusFileSize
new234 bytes

We can remove the Warning: get_class() expects parameter 1 to be object, integer given in date_format_date() caused by date_api.module by using this patch:)

damienmckenna’s picture

Status: Active » Closed (won't fix)

Unfortunately the Drupal 6 version of the Date module is no longer supported. That said, we appreciate that you took time to work on this issue. Should this request still be relevant for Drupal 7 please feel free to reopen it. Thank you.