From 7d9ce8864a30b6f8a0489f5e7f50e04db06797a5 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Mon, 7 Jan 2013 15:40:42 +0000 Subject: [PATCH] MDL-37374 questions: use property_exists rather than isset $a->field = null; isset($a->field) returns false, which is typical PHP. I also improve the error handling a bit. --- question/type/edit_question_form.php | 2 +- question/type/questiontypebase.php | 15 +++------------ 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/question/type/edit_question_form.php b/question/type/edit_question_form.php index 714d6a87009..f0d903e1c80 100644 --- a/question/type/edit_question_form.php +++ b/question/type/edit_question_form.php @@ -481,7 +481,7 @@ abstract class question_edit_form extends question_wizard_form { if (is_array($extraquestionfields) && !empty($question->options)) { array_shift($extraquestionfields); foreach ($extraquestionfields as $field) { - if (isset($question->options->$field)) { + if (property_exists($question->options->$field)) { $question->$field = $question->options->$field; } } diff --git a/question/type/questiontypebase.php b/question/type/questiontypebase.php index 52e42cc7365..f3620fa2679 100644 --- a/question/type/questiontypebase.php +++ b/question/type/questiontypebase.php @@ -454,21 +454,12 @@ class question_type { $options->$questionidcolname = $question->id; } foreach ($extraquestionfields as $field) { - if (!isset($question->$field)) { - $result = new stdClass(); - $result->error = "No data for field $field when saving " . - $this->name() . ' question id ' . $question->id; - return $result; + if (property_exists($question->$field)) { + $options->$field = $question->$field; } - $options->$field = $question->$field; } - if (!$DB->{$function}($question_extension_table, $options)) { - $result = new stdClass(); - $result->error = 'Could not save question options for ' . - $this->name() . ' question id ' . $question->id; - return $result; - } + $DB->{$function}($question_extension_table, $options); } $extraanswerfields = $this->extra_answer_fields();