Skip to content

Commit 600d8a1

Browse files
committed
Internal: Fix various PHP8 compatibility issues to reduce error messages
1 parent c1ef468 commit 600d8a1

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

main/inc/lib/internationalization.lib.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1207,7 +1207,7 @@ function api_htmlentities($string, $quote_style = ENT_COMPAT, $encoding = 'UTF-8
12071207
break;
12081208
}
12091209

1210-
return mb_convert_encoding($string, 'HTML-ENTITIES', 'UTF-8');
1210+
return htmlspecialchars($string);
12111211
}
12121212

12131213
/**

main/inc/lib/system/session.class.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,17 @@ public function offsetExists($offset): bool
128128
}
129129

130130
/**
131-
* It it exists returns the value stored at the specified offset.
132-
* If offset does not exists returns null. Do not trigger a warning.
131+
* If it exists, returns the value stored at the specified offset.
132+
* If offset does not exist, returns null. Do not trigger a warning.
133133
*
134134
* @param string $offset
135135
*
136136
* @return mixed (write offsetGet($offset): mixed on PHP 8 and & > )
137137
*/
138-
public function offsetGet($offset)
138+
#if PHP_VERSION_ID >= 80000
139+
#[\ReturnTypeWillChange]
140+
#endif
141+
public function offsetGet($offset): mixed
139142
{
140143
return self::read($offset);
141144
}

main/install/index.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@
170170
$badUpdatePath = false;
171171
$emptyUpdatePath = true;
172172
$proposedUpdatePath = '';
173+
$updateFromConfigFile = '';
173174

174175
if (!empty($_POST['updatePath'])) {
175176
$proposedUpdatePath = $_POST['updatePath'];
@@ -198,11 +199,10 @@
198199
} elseif (@$_POST['step1']) {
199200
$_POST['updatePath'] = '';
200201
$installType = '';
201-
$updateFromConfigFile = '';
202202
unset($_GET['running']);
203203
} else {
204204
$installType = isset($_GET['installType']) ? $_GET['installType'] : null;
205-
$updateFromConfigFile = isset($_GET['updateFromConfigFile']) ? $_GET['updateFromConfigFile'] : false;
205+
$updateFromConfigFile = isset($_GET['updateFromConfigFile']) ? $_GET['updateFromConfigFile'] : '';
206206
}
207207

208208
if ($installType == 'update' && in_array($my_old_version, $update_from_version_8)) {

src/Chamilo/UserBundle/Entity/User.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,24 @@ public function __toString()
458458
{
459459
return $this->getUsername();
460460
}
461+
public function __serialize(): array
462+
{
463+
return get_object_vars($this);
464+
}
465+
public function __unserialize(array $data): void
466+
{
467+
$reflection = new ReflectionClass($this);
468+
$properties = $reflection->getProperties();
469+
$propertyNames = array_map(fn($prop) => $prop->getName(), $properties);
470+
471+
foreach ($data as $property => $value) {
472+
if (in_array($property, $propertyNames)) {
473+
$this->$property = $value;
474+
} else {
475+
// the attribute does not exist in this version of the class
476+
}
477+
}
478+
}
461479

462480
/**
463481
* Updates the id with the user_id.

0 commit comments

Comments
 (0)