fix php8 fatal error

This commit is contained in:
Frédéric FRANCE 2021-03-13 18:42:50 +01:00
parent 99461b3fa6
commit c3c03e9de3
No known key found for this signature in database
GPG Key ID: 06809324E4B2ABC1
2 changed files with 14 additions and 2 deletions

View File

@ -93,7 +93,7 @@ function dol_setcache($memoryid, $data, $expire = 0)
$dolmemcache->add($memoryid, $data, $expire); // This fails if key already exists
$rescode = $dolmemcache->getResultCode();
if ($rescode == 0) {
return count($data);
return is_countable($data) ? count($data) : 0;
} else {
return -$rescode;
}
@ -113,7 +113,7 @@ function dol_setcache($memoryid, $data, $expire = 0)
//$dolmemcache->setOption(Memcached::OPT_COMPRESSION, false);
$result = $dolmemcache->add($memoryid, $data, false, $expire); // This fails if key already exists
if ($result) {
return count($data);
return is_countable($data) ? count($data) : 0;
} else {
return -1;
}

View File

@ -48,6 +48,18 @@ if (!empty($_SERVER['MAIN_SHOW_TUNING_INFO'])) {
}
}
if (!function_exists('is_countable')) {
/**
* function is_countable (to remove when php version supported will be >= 7.3)
* @param mixed $c data to check if countable
* @return bool
*/
function is_countable($c)
{
return is_array($c) || $c instanceof Countable;
}
}
/**
* Security: WAF layer for SQL Injection and XSS Injection (scripts) protection (Filters on GET, POST, PHP_SELF).
* Warning: Such a protection can't be enough. It is not reliable as it will alwyas be possible to bypass this. Good protection can