Skip to content

Commit fab95ce

Browse files
committed
MDL-86655 lib: Preserve native booleans in PARAM_BOOL cleaning
Return true/false for boolean inputs instead of 0/1, keeping strict comparisons and schema validation correct.
1 parent 81aac90 commit fab95ce

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

lib/classes/param.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -798,20 +798,19 @@ protected function clean_param_value_sequence(mixed $param): mixed {
798798
* Validation for PARAM_BOOL.
799799
*
800800
* @param mixed $param
801-
* @return mixed
801+
* @return bool
802802
*/
803-
protected function clean_param_value_bool(mixed $param): mixed {
804-
// Convert to 1 or 0 or bool.
803+
protected function clean_param_value_bool(mixed $param): bool {
805804
if (is_bool($param)) {
806-
return $param ? true : false;
805+
return $param;
807806
}
808807
$tempstr = strtolower((string)$param);
809-
if ($tempstr === 'on' || $tempstr === 'yes' || $tempstr === 'true') {
810-
$param = 1;
811-
} else if ($tempstr === 'off' || $tempstr === 'no' || $tempstr === 'false') {
812-
$param = 0;
808+
if ($tempstr === 'on' || $tempstr === 'yes') {
809+
$param = true;
810+
} else if ($tempstr === 'off' || $tempstr === 'no') {
811+
$param = false;
813812
} else {
814-
$param = empty($param) ? 0 : 1;
813+
$param = empty($param) ? false : true;
815814
}
816815
return $param;
817816
}

0 commit comments

Comments
 (0)