MDL-70920 core: prevent calls to call_user_fun_array() with assoc array
This commit is contained in:
@@ -8062,6 +8062,16 @@ function component_callback($component, $function, array $params = array(), $def
|
||||
|
||||
$functionname = component_callback_exists($component, $function);
|
||||
|
||||
if ($params && (array_keys($params) !== range(0, count($params) - 1))) {
|
||||
// PHP 8 allows to have associative arrays in the call_user_func_array() parameters but
|
||||
// PHP 7 does not. Using associative arrays can result in different behavior in different PHP versions.
|
||||
// See https://php.watch/versions/8.0/named-parameters#named-params-call_user_func_array
|
||||
// This check can be removed when minimum PHP version for Moodle is raised to 8.
|
||||
debugging('Parameters array can not be an associative array while Moodle supports both PHP 7 and PHP 8.',
|
||||
DEBUG_DEVELOPER);
|
||||
$params = array_values($params);
|
||||
}
|
||||
|
||||
if ($functionname) {
|
||||
// Function exists, so just return function result.
|
||||
$ret = call_user_func_array($functionname, $params);
|
||||
|
||||
Reference in New Issue
Block a user