Reputation: 197
i have this error after upgrade to php 7.1
PHP Warning: A non-numeric value encountered in public_html/wp-includes/formatting.php on line 3221
here the code on that file.
function human_time_diff( $from, $to = '' ) {
if ( empty( $to ) ) {
$to = time();
}
//line 3221
$diff = (int) abs( $to - $from );
Upvotes: 1
Views: 1368
Reputation: 16436
PHP 7 stritcly chek datatype when you do operations like this: You can change function as below
function human_time_diff( $from, $to = '' ) {
if ( empty( $to ) || ! is_numeric( $to )) {
$to = time();
}
//check for from may be its valid date format but not time stamp
if( ! is_numeric( $from ) ) {
if(strtotime($from)){
$from = strtotime($from);
}
else{
return 'Error: In valid from date.';
}
}
//line 3221
$diff = (int) abs( $to - $from );
Upvotes: 1
Reputation: 4582
Just do a little more checking to see if the variables are numeric:
function human_time_diff( $from, $to = '' )
{
if( ! is_numeric( $to ) OR empty( $to ) ) {
$to = time();
}
if( ! is_numeric( $from ) ) {
return 'Error: From must be numeric.';
}
$diff = (int) abs( $to - $from );
return $diff;
}
Upvotes: 2