1

We recently updated our shared hosting to use PHP 7.3 (problem still existed in PHP 7.2 as well) - website is throwing the error in the title.

the function in question is:

function current_time( $type, $gmt = 0 ) {
switch ( $type ) {
    case 'mysql':
        return ( $gmt ) ? gmdate( 'Y-m-d H:i:s' ) : gmdate( 'Y-m-d H:i:s', ( time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) ) );
    case 'timestamp':
        return ( $gmt ) ? time() : time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
    default:
        return ( $gmt ) ? gmdate( $type ) : gmdate( $type, time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) );
}}

Line 68 is:

return ( $gmt ) ? gmdate( 'Y-m-d H:i:s' ) : gmdate( 'Y-m-d H:i:s', ( time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) ) );

The functions file has not been modified - any ideas what is causing this?

2
  • 1
    Try to re-save the "General" settings - make sure a proper timezone is selected. If that doesn't help, then the HOUR_IN_SECONDS constant is probably not a numeric.. – Sally CJ Oct 1 '19 at 20:52
  • 2
    Really? Wow! That was it. I simply needed to reselect my time and date options in general settings and save. Thank you so much! – Ben McCoy Oct 2 '19 at 14:10
0

There is another question dealing with a slightly more complicated issue than yours, but it contains a lesson.

Basically, what I learned is that you should process your equation in two or more steps, to account for gmt_offset being returned as a string:

$offset  = get_option( 'gmt_offset' );
$hours   = (int) $offset;

return ( $gmt ) ? gmdate( 'Y-m-d H:i:s' ) : gmdate( 'Y-m-d H:i:s', ( time() + ( $hours * HOUR_IN_SECONDS ) ) );

This should avoid the error you are seeing.

Good luck!

1
  • 1
    The function in the question is a core function. They can't modify it. – Jacob Peattie Oct 2 '19 at 2:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.