MDL-72329 core: Persistent method get needs to return correct type

This commit is contained in:
David Matamoros
2021-09-24 08:45:08 +02:00
parent 214adb7984
commit 78735a72bc
3 changed files with 124 additions and 1 deletions
+12 -1
View File
@@ -143,7 +143,18 @@ abstract class persistent {
if (method_exists($this, $methodname)) {
return $this->$methodname();
}
return $this->raw_get($property);
$properties = static::properties_definition();
// If property can be NULL and value is NULL it needs to return null.
if ($properties[$property]['null'] === NULL_ALLOWED && $this->raw_get($property) === null) {
return null;
}
// Deliberately cast boolean types as such, because clean_param will cast them to integer.
if ($properties[$property]['type'] === PARAM_BOOL) {
return (bool)$this->raw_get($property);
}
return clean_param($this->raw_get($property), $properties[$property]['type']);
}
/**