From c3c03e9de3acd12341d6ab6d4d137a9fd50603d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sat, 13 Mar 2021 18:42:50 +0100 Subject: [PATCH 1/2] fix php8 fatal error --- htdocs/core/lib/memory.lib.php | 4 ++-- htdocs/main.inc.php | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/htdocs/core/lib/memory.lib.php b/htdocs/core/lib/memory.lib.php index ce603415009..1300c1b771f 100644 --- a/htdocs/core/lib/memory.lib.php +++ b/htdocs/core/lib/memory.lib.php @@ -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; } diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index f72a933c688..2c799e21591 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -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 From 29d86adcb3659a06bed0da6808a01009f0170e1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Mon, 15 Mar 2021 11:20:15 +0100 Subject: [PATCH 2/2] move function declaration --- htdocs/main.inc.php | 12 ------------ htdocs/master.inc.php | 11 +++++++++++ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index 336748d0c03..31fbc0ee4b3 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -49,18 +49,6 @@ 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 diff --git a/htdocs/master.inc.php b/htdocs/master.inc.php index c63ace353b3..371d687b9b7 100644 --- a/htdocs/master.inc.php +++ b/htdocs/master.inc.php @@ -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