[wp-trac] [WordPress Trac] #57035: Error in current_time() function when using timestamp and no value for gmt_offset

WordPress Trac noreply at wordpress.org
Tue Nov 8 13:28:40 UTC 2022


#57035: Error in current_time() function when using timestamp and no value for
gmt_offset
--------------------------+-----------------------------
 Reporter:  Nick_theGeek  |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  6.1
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 This may be a but of an edge case, but if the gmt_offset is not set
 correctly a string is returned and then used in math to multiply against
 HOUR_IN_SECONDS.

 In PHP 7 and earlier this is dismissed as a warning so processing
 continues, but in PHP 8 this throws a fatal error.

 It looks like the function has some typecasting, but it is placed in the
 wrong spot.

 `
         // Don't use non-GMT timestamp, unless you know the difference and
 really need to.
         if ( 'timestamp' === $type || 'U' === $type ) {
                 return $gmt ? time() : time() + (int) ( get_option(
 'gmt_offset' ) * HOUR_IN_SECONDS );
         }
 `

 Should be

 `
         // Don't use non-GMT timestamp, unless you know the difference and
 really need to.
         if ( 'timestamp' === $type || 'U' === $type ) {
                 return $gmt ? time() : time() + ( (int) get_option(
 'gmt_offset' ) * HOUR_IN_SECONDS );
         }
 `

 Again, this is potentially an edge case. Another ticket was reported and
 closed when the user discovered a work around, but I think this fix is
 pretty simple and will solve for weird edge cases that can break sites in
 php8.
 https://core.trac.wordpress.org/ticket/56358

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/57035>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list