Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-30167 qtype_numerical: notice when required unit is not in the an…

…swer.
  • Loading branch information...
commit 4493fe9c90e5660e28b4caad986efded7bb1fcf8 1 parent e25ecdf
@timhunt timhunt authored
Showing with 4 additions and 3 deletions.
  1. +4 −3 question/type/numerical/questiontype.php
View
7 question/type/numerical/questiontype.php
@@ -641,16 +641,17 @@ public function apply_units($response, $separateunit = null) {
$numberstring = $matches[0];
if ($this->unitsbefore) {
- $unit = substr($response, 0, -strlen($numberstring));
+ // substr returns false when it means '', so cast back to string.
+ $unit = (string) substr($response, 0, -strlen($numberstring));
} else {
- $unit = substr($response, strlen($numberstring));
+ $unit = (string) substr($response, strlen($numberstring));
}
if (!is_null($separateunit)) {
$unit = $separateunit;
}
- if ($unit && $this->is_known_unit($unit)) {
+ if ($this->is_known_unit($unit)) {
$multiplier = 1 / $this->units[$unit];
} else {
$multiplier = null;
Please sign in to comment.
Something went wrong with that request. Please try again.