From be492e2a8f2eed8e044b2099cbfd043f9f755f66 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Tue, 2 Apr 2019 14:12:45 +0100 Subject: [PATCH] MDL-65245 question engine: response vars should always be PHP strings --- question/engine/questionattempt.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/question/engine/questionattempt.php b/question/engine/questionattempt.php index 1a9bd04633b..efc5425d045 100644 --- a/question/engine/questionattempt.php +++ b/question/engine/questionattempt.php @@ -1069,6 +1069,13 @@ class question_attempt { $var = null; } + if ($var !== null) { + // Ensure that, if set, $var is a string. This is because later, after + // it has been saved to the database and loaded back it will be a string, + // so better if the type is predictably always a string. + $var = (string) $var; + } + return $var; } }