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.
This commit is contained in:
Tim Hunt
2013-01-11 13:04:31 +00:00
parent 8a646b55f7
commit 4dcede552e
2 changed files with 4 additions and 13 deletions
+1 -1
View File
@@ -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;
}
}
+3 -12
View File
@@ -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();