From 5fbbb51882e3a5ee4fe2cd454efd61dbd76711b0 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Fri, 6 Jan 2023 21:10:51 +0800 Subject: [PATCH] MDL-76362 core: Use empty default string when getting prefs 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. --- course/format/classes/base.php | 2 +- lib/tablelib.php | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/course/format/classes/base.php b/course/format/classes/base.php index bc8a6d69ef7..26000882a46 100644 --- a/course/format/classes/base.php +++ b/course/format/classes/base.php @@ -608,7 +608,7 @@ abstract class base { $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 = []; diff --git a/lib/tablelib.php b/lib/tablelib.php index bf099cd9066..b9b593a7ffa 100644 --- a/lib/tablelib.php +++ b/lib/tablelib.php @@ -573,7 +573,7 @@ class flexible_table { 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 ''; } @@ -1463,7 +1463,7 @@ class flexible_table { // 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]; @@ -2346,4 +2346,3 @@ class table_dataformat_export_format extends table_default_export_format_parent exit(); } } -