A non-numeric value encountered in wp-includesfunctions.php on line 68

admin2025-01-07  3

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?

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?

Share Improve this question asked Oct 1, 2019 at 20:02 Ben McCoyBen McCoy 113 bronze badges 2
  • 2 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 Commented Oct 1, 2019 at 20:52
  • 3 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 Commented Oct 2, 2019 at 14:10
Add a comment  | 

1 Answer 1

Reset to default 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!

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736258614a527.html

最新回复(0)