在PHP 7.1
问题描述:
非数值出现的错误,我有这个错误后升级到PHP 7.1在PHP 7.1
PHP Warning: A non-numeric value encountered in public_html/wp-includes/formatting.php on line 3221
这里该文件的代码。
function human_time_diff($from, $to = '') {
if (empty($to)) {
$to = time();
}
//line 3221
$diff = (int) abs($to - $from);
答
PHP 7,当你做这样的操作stritcly赤数据类型:您可以更改功能如下
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);
答
只要做一点点更多的检查,看看是否变量数值:
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;
}
是从约会?在这种情况下,from是一个字符串,你可以减去字符串或字符串和整数 – Andreas