Skip to content

Commit

Permalink
Internal: Fix various PHP8 compatibility issues to reduce error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
ywarnier committed Dec 16, 2024
1 parent c1ef468 commit 600d8a1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion main/inc/lib/internationalization.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
9 changes: 6 additions & 3 deletions main/inc/lib/system/session.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions main/install/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@
$badUpdatePath = false;
$emptyUpdatePath = true;
$proposedUpdatePath = '';
$updateFromConfigFile = '';

if (!empty($_POST['updatePath'])) {
$proposedUpdatePath = $_POST['updatePath'];
Expand Down Expand Up @@ -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)) {
Expand Down
18 changes: 18 additions & 0 deletions src/Chamilo/UserBundle/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 600d8a1

Please sign in to comment.