警告:count():必须是实现 Countable 的数组或对象

Warning: count(): must be an array or object that implements Countable

我已经迁移到使用 PHP v7(来自我的 PHP v5.4)的新服务器,现在我的网站上显示错误。

这是返回错误的代码行:

// The value of $ip at this point would look something like: "192.0.34.166"
$ip = ip2long($ip);
// The $ip would now look something like: 1073732954
if(!count($ip) > 0 || !preg_match('/^\d+$/', $ip) || empty($ip)) {
    $ip="0000000000";
}

我该如何解决?

ip2long 从未返回数组。我认为您可以安全地从您的条件中删除 !count($ip) > 0 ||