Make WordPress Core

Opened 19 months ago

Closed 19 months ago

Last modified 6 months ago

#56358 closed defect (bug) (invalid)

PHP8 TypeError on current_time( 'timestamp' ) if timezone is set to GMT / 0

Reported by: toastercookie's profile toastercookie Owned by:
Milestone: Priority: normal
Severity: minor Version: 6.0
Component: Date/Time Keywords: php8
Focuses: Cc:

Description

Just a minor bug to report, seems that if you have your timezone set to GMT, current_time( 'timestamp' ) throws a fatal error on PHP8, I think because 0 is being sent as a string. I can fix by changing my timezone to anything else.

PHP Fatal error: Uncaught TypeError: Unsupported operand types: string * int in /wp-includes/functions.php:75
Stack trace: #0 /RSSItemPull.php(286): current_time('timestamp')

Change History (5)

#1 @Rarst
19 months ago

Do you mean UTC? GMT is currently not an option in WordPress time zone settings and I can't reproduce it on PHP 8.1.

I do not see how this error could happen with current version of the current_time() code. Which WordPress version are you on?

I do see that option could return "0" there (for UTC+0 time zone). However, from quick check, multiplying that by an integer is a valid operation in PHP 8, it would type cast it to a number. https://3v4l.org/sGXiQ

Last edited 19 months ago by Rarst (previous) (diff)

#2 in reply to: ↑ description @SergeyBiryukov
19 months ago

Hi there, welcome to WordPress Trac! Thanks for the ticket.

Replying to toastercookie:

Just a minor bug to report, seems that if you have your timezone set to GMT, current_time( 'timestamp' ) throws a fatal error on PHP8, I think because 0 is being sent as a string. I can fix by changing my timezone to anything else.

I could not reproduce the error in my testing. As noted above, '0' should not be an issue, as it is still a numeric string.
Could you look into what get_option( 'gmt_offset' ) returns, or what is the value in the wp_options table?

I can only reproduce this with a non-numeric string like Europe/London, but that should be in the timezone_string option, not in gmt_offset. Does the issue still happen on a clean install, with all plugins disabled and a default theme (Twenty Twenty-Two) activated?

Replying to Rarst:

Do you mean UTC? GMT is currently not an option in WordPress time zone settings and I can't reproduce it on PHP 8.1.

It looks like the English (UK) locale translates UTC as GMT.

#3 @toastercookie
19 months ago

  • Resolution set to invalid
  • Status changed from new to closed

Changing the timezone and then changing it back seems to have fixed it for me, so there must have been something weird in my DB being returned. I can't reproduce this on my end anymore so I will just go ahead and close this! Sorry for wasting yall's time

#4 @SergeyBiryukov
19 months ago

  • Keywords php8 added
  • Milestone Awaiting Review deleted

No worries, thanks for the follow-up!

Note: See TracTickets for help on using tickets.