Merge pull request #16648 from frederic34/php8-fix

fix php8 fatal error
This commit is contained in:
Laurent Destailleur 2021-03-15 11:26:44 +01:00 committed by GitHub
commit cb9d661158
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 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

@ -35,6 +35,17 @@
require_once 'filefunc.inc.php'; // May have been already require by main.inc.php. But may not by scripts.
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;
}
}
/*
* Create $conf object