Skip to content

Commit

Permalink
MDL-76362 core: Use empty default string when getting prefs
Browse files Browse the repository at this point in the history
The json_decode function does not accept a null, which is the
traditional default for get_user_preferences. By passing a default of
am empty string we avoid issues in PHP 8.1.
  • Loading branch information
andrewnicols committed Jan 23, 2023
1 parent b0a83aa commit ef09257
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion course/format/classes/base.php
Expand Up @@ -618,7 +618,7 @@ public function get_sections_preferences_by_preference(): array {
$course = $this->get_course();
try {
$sectionpreferences = (array) json_decode(
get_user_preferences('coursesectionspreferences_' . $course->id, null, $USER->id) ?? ''
get_user_preferences("coursesectionspreferences_{$course->id}", '', $USER->id)
);
if (empty($sectionpreferences)) {
$sectionpreferences = [];
Expand Down
5 changes: 2 additions & 3 deletions lib/tablelib.php
Expand Up @@ -573,7 +573,7 @@ public static function get_sort_for_table($uniqueid) {
global $SESSION;
if (isset($SESSION->flextable[$uniqueid])) {
$prefs = $SESSION->flextable[$uniqueid];
} else if (!$prefs = json_decode(get_user_preferences('flextable_' . $uniqueid), true)) {
} else if (!$prefs = json_decode(get_user_preferences("flextable_{$uniqueid}", ''), true)) {
return '';
}

Expand Down Expand Up @@ -1463,7 +1463,7 @@ protected function initialise_table_preferences(): void {

// Load any existing user preferences.
if ($this->persistent) {
$this->prefs = json_decode(get_user_preferences('flextable_' . $this->uniqueid) ?? '', true);
$this->prefs = json_decode(get_user_preferences("flextable_{$this->uniqueid}", ''), true);
$oldprefs = $this->prefs;
} else if (isset($SESSION->flextable[$this->uniqueid])) {
$this->prefs = $SESSION->flextable[$this->uniqueid];
Expand Down Expand Up @@ -2346,4 +2346,3 @@ public function finish_document() {
exit();
}
}

0 comments on commit ef09257

Please sign in to comment.