From 05e6cfa8c1b65b1f52d4aacb436dfbebc8bf5474 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 20 Sep 2022 21:15:25 +0200 Subject: [PATCH] Fix compatibility with PHP 8.1 and Psotgresql --- htdocs/core/lib/functions.lib.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index e6c69cadc96..d76e23facdc 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -1156,7 +1156,17 @@ function dol_buildpath($path, $type = 0, $returnemptyifnotfound = 0) function dol_clone($object, $native = 0) { if (empty($native)) { + $tmpsavdb = null; + if (isset($object->db) && isset($object->db->db) && is_object($object->db->db) && get_class($object->db->db) == 'PgSql\Connection') { + $tmpsavdb = $object->db; + unset($object->db); // Such property can not be serialized when PgSql/Connection + } + $myclone = unserialize(serialize($object)); // serialize then unserialize is hack to be sure to have a new object for all fields + + if ($tmpsavdb) { + $object->db = $tmpsavdb; + } } else { $myclone = clone $object; // PHP clone is a shallow copy only, not a real clone, so properties of references will keep the reference (refering to the same target/variable) }