Skip to content

Commit

Permalink
MDL-37374 questions: use property_exists rather than isset
Browse files Browse the repository at this point in the history
$a->field = null; isset($a->field) returns false, which is typical PHP.
I also improve the error handling a bit.
  • Loading branch information
timhunt committed Jan 11, 2013
1 parent dbee98b commit 7d9ce88
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
2 changes: 1 addition & 1 deletion question/type/edit_question_form.php
Expand Up @@ -481,7 +481,7 @@ public function set_data($question) {
if (is_array($extraquestionfields) && !empty($question->options)) { if (is_array($extraquestionfields) && !empty($question->options)) {
array_shift($extraquestionfields); array_shift($extraquestionfields);
foreach ($extraquestionfields as $field) { foreach ($extraquestionfields as $field) {
if (isset($question->options->$field)) { if (property_exists($question->options->$field)) {
$question->$field = $question->options->$field; $question->$field = $question->options->$field;
} }
} }
Expand Down
15 changes: 3 additions & 12 deletions question/type/questiontypebase.php
Expand Up @@ -454,21 +454,12 @@ public function save_question_options($question) {
$options->$questionidcolname = $question->id; $options->$questionidcolname = $question->id;
} }
foreach ($extraquestionfields as $field) { foreach ($extraquestionfields as $field) {
if (!isset($question->$field)) { if (property_exists($question->$field)) {
$result = new stdClass(); $options->$field = $question->$field;
$result->error = "No data for field $field when saving " .
$this->name() . ' question id ' . $question->id;
return $result;
} }
$options->$field = $question->$field;
} }


if (!$DB->{$function}($question_extension_table, $options)) { $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;
}
} }


$extraanswerfields = $this->extra_answer_fields(); $extraanswerfields = $this->extra_answer_fields();
Expand Down

0 comments on commit 7d9ce88

Please sign in to comment.