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.
| Comment | File | Size | Author |
|---|---|---|---|
| #12 | date-n2880395-11.patch | 2.91 KB | damienmckenna |
| #9 | date-n2880395-9.patch | 2.93 KB | damienmckenna |
| #9 | date-n2880395-9.interdiff.txt | 840 bytes | damienmckenna |
| #5 | date-datetimezone-converted-to-string-2325207-24.patch | 4.4 KB | jojonaloha |
| #2 | date-datetimezone-converted-to-string-2325207-22--tests-only.patch | 3.39 KB | jojonaloha |
Comments
Comment #2
jojonaloha commentedOriginal patch that only includes tests from #2325207-22: DateTimeZone could not be converted to string
This should fail, proving the bug still exists.
Comment #3
jojonaloha commentedComment #5
jojonaloha commentedAnd the original patch from https://www.drupal.org/node/2325207#comment-10543380 with tests that should pass.
Comment #7
jojonaloha commentedPutting back to Needs Review because the new test passes and the code sniffer changes have nothing to do with the changes made in this patch.
Comment #8
goz commentedI have the same issue. Patch apply and works as expected.
Thanks jojonaloha.
Comment #9
damienmckennaA slight tidying of the test's setUp() method.
Comment #10
damienmckennaComment #12
damienmckennaApologies, I didn't realize that DrupalUnitTestCase required the setUp() method use drupal_load() to load modules.
Comment #14
damienmckennaCommitted. Thanks!
Comment #15
damienmckenna