This was originally reported in #2325207: DateTimeZone could not be converted to string and supposedly fixed in 7.x-2.10, however the applied "fix" never actually fixed this fatal error, as demonstrated by the tests #2325207-22: DateTimeZone could not be converted to string.

Since I cannot re-open that issue, this is a "follow-up" issue for the same bug.

Original report by bugster

Recoverable fatal error: Object of class DateTimeZone could not be converted to string in date_now() (line 1753 of modules/date/date_api/date_api.module).

I do have php 5.5.9, I guess they removed the __toString function from this class

Cause reported by jojonaloha in #2325207-2: DateTimeZone could not be converted to string

This bug was introduced in #2261395: date_now is not respecting changes to timezone.

The reason is DateTimeZone doesn't have a __toString() method and the issue assumed it was always a string, even though the code comment suggests it is always an object.

Proposed Fix

Update the code comment to better reflect the accepted parameters (same as the DateObject constructor)
Add tests to prove the bug exists and prevent it from being re-introduced
Fix the bug by handling DateTimeZone objects when building the static variable name.

Comments

jojonaloha created an issue. See original summary.

jojonaloha’s picture

Original patch that only includes tests from #2325207-22: DateTimeZone could not be converted to string

This should fail, proving the bug still exists.