From 600d8a1a9269b21c4d5ba78f04c2a34e60fd2688 Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Mon, 16 Dec 2024 14:54:39 +0100 Subject: [PATCH] Internal: Fix various PHP8 compatibility issues to reduce error messages --- main/inc/lib/internationalization.lib.php | 2 +- main/inc/lib/system/session.class.php | 9 ++++++--- main/install/index.php | 4 ++-- src/Chamilo/UserBundle/Entity/User.php | 18 ++++++++++++++++++ 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/main/inc/lib/internationalization.lib.php b/main/inc/lib/internationalization.lib.php index e72984b1acf..9976e7740fc 100755 --- a/main/inc/lib/internationalization.lib.php +++ b/main/inc/lib/internationalization.lib.php @@ -1207,7 +1207,7 @@ function api_htmlentities($string, $quote_style = ENT_COMPAT, $encoding = 'UTF-8 break; } - return mb_convert_encoding($string, 'HTML-ENTITIES', 'UTF-8'); + return htmlspecialchars($string); } /** diff --git a/main/inc/lib/system/session.class.php b/main/inc/lib/system/session.class.php index fa50bc50c59..414312c4cac 100755 --- a/main/inc/lib/system/session.class.php +++ b/main/inc/lib/system/session.class.php @@ -128,14 +128,17 @@ public function offsetExists($offset): bool } /** - * It it exists returns the value stored at the specified offset. - * If offset does not exists returns null. Do not trigger a warning. + * If it exists, returns the value stored at the specified offset. + * If offset does not exist, returns null. Do not trigger a warning. * * @param string $offset * * @return mixed (write offsetGet($offset): mixed on PHP 8 and & > ) */ - public function offsetGet($offset) + #if PHP_VERSION_ID >= 80000 + #[\ReturnTypeWillChange] + #endif + public function offsetGet($offset): mixed { return self::read($offset); } diff --git a/main/install/index.php b/main/install/index.php index 66741de5564..234736762e0 100755 --- a/main/install/index.php +++ b/main/install/index.php @@ -170,6 +170,7 @@ $badUpdatePath = false; $emptyUpdatePath = true; $proposedUpdatePath = ''; +$updateFromConfigFile = ''; if (!empty($_POST['updatePath'])) { $proposedUpdatePath = $_POST['updatePath']; @@ -198,11 +199,10 @@ } elseif (@$_POST['step1']) { $_POST['updatePath'] = ''; $installType = ''; - $updateFromConfigFile = ''; unset($_GET['running']); } else { $installType = isset($_GET['installType']) ? $_GET['installType'] : null; - $updateFromConfigFile = isset($_GET['updateFromConfigFile']) ? $_GET['updateFromConfigFile'] : false; + $updateFromConfigFile = isset($_GET['updateFromConfigFile']) ? $_GET['updateFromConfigFile'] : ''; } if ($installType == 'update' && in_array($my_old_version, $update_from_version_8)) { diff --git a/src/Chamilo/UserBundle/Entity/User.php b/src/Chamilo/UserBundle/Entity/User.php index f040d84faa7..247bbf54c38 100644 --- a/src/Chamilo/UserBundle/Entity/User.php +++ b/src/Chamilo/UserBundle/Entity/User.php @@ -458,6 +458,24 @@ public function __toString() { return $this->getUsername(); } + public function __serialize(): array + { + return get_object_vars($this); + } + public function __unserialize(array $data): void + { + $reflection = new ReflectionClass($this); + $properties = $reflection->getProperties(); + $propertyNames = array_map(fn($prop) => $prop->getName(), $properties); + + foreach ($data as $property => $value) { + if (in_array($property, $propertyNames)) { + $this->$property = $value; + } else { + // the attribute does not exist in this version of the class + } + } + } /** * Updates the id with the user_id.