Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comments
Comment #1
bugster CreditAttribution: bugster commentedIf you don't pass a DateTimeZone object but the string timezone, it does not fail. DateObject also accepts the string version.
Guess the documentation is a bit misleading @param object $timezone.
Comment #2
jojonaloha CreditAttribution: jojonaloha commentedThis 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.
Attached patch updates the code comment to better reflect the accepted parameters (same as the DateObject constructor), and fixes the bug by handling DateTimeZone objects when building the static variable name.
Comment #5
jojonaloha CreditAttribution: jojonaloha commentedRe-rolled patch attached.
Comment #6
Yurii Krysiuk CreditAttribution: Yurii Krysiuk commentedComment #7
Yurii Krysiuk CreditAttribution: Yurii Krysiuk commentedComment #9
moymilo CreditAttribution: moymilo as a volunteer commentedReviewed patch and manualy tested, looks like all work fine.
Comment #10
podarokPlease, use Early define pattern here
Example:
https://github.com/propeoplemd/cibox/wiki/PHP-JavaScript-SCSS-SASS-best-...
Comment #11
v1nk CreditAttribution: v1nk as a volunteer commentedComment #12
andypostshould be in else
if (instance) use getName()
else concatenation
Comment #13
v1nk CreditAttribution: v1nk as a volunteer commented@andypost
Removed else regarding @podarok comment. So how it should be right ?
Comment #15
podarokThanks @v1nk , #11 committed
Comment #16
jojonaloha CreditAttribution: jojonaloha commentedSorry, but #11 does not fix the issue, it just adds more code that suffers from the same problem. I think a test is needed.
Comment #17
StevenWill CreditAttribution: StevenWill commentedThe patch from #5 fixed the issue for me.
Comment #18
podarok@jojonaloha can you please be more specific with a real example of the problem?
Thanks in advance
Comment #19
jojonaloha CreditAttribution: jojonaloha commentedAttached is a patch with a simpletest. This is my first time writing a SimpleTest test, and the tests are purely sanity checks, but do fail on the exception.
First patch contains only the test, second patch contains the test and a re-roll of my originally proposed fix.
Comment #22
jojonaloha CreditAttribution: jojonaloha commentedLet's try this again. This one should fail.
Comment #24
jojonaloha CreditAttribution: jojonaloha commentedThis one should pass.
Comment #26
Sebastien M. CreditAttribution: Sebastien M. as a volunteer and at Actualys commentedHere is an update of the #24 patch, but matching to date-7.x-2.9 release.
Hope it helps,
Thanks
Comment #29
jojonaloha CreditAttribution: jojonaloha as a volunteer and commentedPatch #24 is still passing and the one to be used against 7.x-2.x-dev. Moving back to needs review.
Comment #30
Sebastien M. CreditAttribution: Sebastien M. as a volunteer and at Actualys commentedWhat about this issue ?
Comment #31
Sebastien M. CreditAttribution: Sebastien M. as a volunteer and at Actualys commented#26 is only provided to work on 7.x-2.9.
Comment #32
RoSk0Assuming fixed because included in 7.x-2.10 release.
@Sebastien @Actualys Please create a follow up issue if you think that there is something to be fixed.
Comment #34
jojonaloha CreditAttribution: jojonaloha as a volunteer and commentedThis is not fixed. If you applied the patch in #22, which only includes a test, and ran the tests you would see the exception described in this ticket still. See attached screenshot (against a fresh Drupal 7.54 install and Date 7.x-dev + the patch in #22).
I've also re-ran the tests with the patch in #24 and it passes. So #24 is still the patch to use to fix this issue. Please re-open this issue as it is not fixed, 7.x-2.10 only included the patch in #11 which still suffers from this bug, as does the latest dev version.
Comment #35
jojonaloha CreditAttribution: jojonaloha as a volunteer and commentedI've opened #2880395: Fatal error: DateTimeZone could not be converted to string as a follow-up to this issue since this one is closed and I cannot re-open it.