Commit 484b43f4 authored by Marina Glancy's avatar Marina Glancy
Browse files

MDL-60281 general: create_function is deprecated in PHP7.2

parent 2abb1e88
......@@ -42,8 +42,9 @@ class auth_ldap_admin_setting_special_contexts_configtext extends admin_setting_
public function write_setting($data) {
// Try to remove duplicates before storing the contexts (to avoid problems in sync_users()).
$data = explode(';', $data);
$data = array_map(create_function('$x', 'return core_text::strtolower(trim($x));'),
$data);
$data = array_map(function($x) {
return core_text::strtolower(trim($x));
}, $data);
$data = implode(';', array_unique($data));
return parent::write_setting($data);
}
......
......@@ -98,7 +98,9 @@ if (count($acceptedroles) > 1) {
} else {
// Get all the roles that user has and use the ones required by this badge.
$roles = get_user_roles($context, $USER->id);
$roleids = array_map(create_function('$o', 'return $o->roleid;'), $roles);
$roleids = array_map(function($o) {
return $o->roleid;
}, $roles);
$selection = array_intersect($acceptedroles, $roleids);
}
......
......@@ -383,7 +383,9 @@ abstract class award_criteria {
$params = array_filter($params);
// Find out which param matches optional and required ones.
$match = array_merge($this->optional_params, array($this->required_param));
$regex = implode('|', array_map(create_function('$a', 'return $a . "_";'), $match));
$regex = implode('|', array_map(function($a) {
return $a . "_";
}, $match));
$requiredkeys = preg_grep('/^(' . $regex . ').*$/', array_keys($params));
if ($this->id !== 0) {
......
......@@ -65,7 +65,9 @@ class award_criteria_manual extends award_criteria {
$none = true;
$roles = get_roles_with_capability('moodle/badges:awardbadge', CAP_ALLOW, $PAGE->context);
$roleids = array_map(create_function('$o', 'return $o->id;'), $roles);
$roleids = array_map(function($o) {
return $o->id;
}, $roles);
$existing = array();
$missing = array();
......
......@@ -62,7 +62,9 @@ class award_criteria_profile extends award_criteria {
// Get custom fields.
$cfields = $DB->get_records_sql($sql);
$cfids = array_map(create_function('$o', 'return $o->fieldid;'), $cfields);
$cfids = array_map(function($o) {
return $o->fieldid;
}, $cfields);
if ($this->id !== 0) {
$existing = array_keys($this->params);
......
......@@ -358,7 +358,9 @@ class core_badges_renderer extends plugin_renderer_base {
// Print evidence.
$agg = $badge->get_aggregation_methods();
$evidence = $badge->get_criteria_completions($userinfo->id);
$eids = array_map(create_function('$o', 'return $o->critid;'), $evidence);
$eids = array_map(function($o) {
return $o->critid;
}, $evidence);
unset($badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]);
$items = array();
......
......@@ -289,8 +289,12 @@ class block_activity_results extends block_base {
}
// Sort groupgrades according to average grade, ascending.
uasort($groupgrades, create_function('$a, $b',
'if($a["average"] == $b["average"]) return 0; return ($a["average"] > $b["average"] ? 1 : -1);'));
uasort($groupgrades, function($a, $b) {
if ($a["average"] == $b["average"]) {
return 0;
}
return ($a["average"] > $b["average"] ? 1 : -1);
});
// How many groups do we have with graded member submissions to show?
$numbest = empty($this->config->showbest) ? 0 : min($this->config->showbest, count($groupgrades));
......
......@@ -234,7 +234,9 @@ function cohort_get_available_cohorts($currentcontext, $withmembers = 0, $offset
// Build context subquery. Find the list of parent context where user is able to see any or visible-only cohorts.
// Since this method is normally called for the current course all parent contexts are already preloaded.
$contextsany = array_filter($currentcontext->get_parent_context_ids(),
create_function('$a', 'return has_capability("moodle/cohort:view", context::instance_by_id($a));'));
function($a) {
return has_capability("moodle/cohort:view", context::instance_by_id($a));
});
$contextsvisible = array_diff($currentcontext->get_parent_context_ids(), $contextsany);
if (empty($contextsany) && empty($contextsvisible)) {
// User does not have any permissions to view cohorts.
......
......@@ -1866,7 +1866,7 @@ abstract class admin_setting {
}
$callbackfunction = $this->updatedcallback;
if (!empty($callbackfunction) and function_exists($callbackfunction)) {
if (!empty($callbackfunction) and is_callable($callbackfunction)) {
$callbackfunction($this->get_full_name());
}
return true;
......@@ -5206,8 +5206,9 @@ class admin_setting_special_coursecontact extends admin_setting_pickroles {
parent::__construct('coursecontact', get_string('coursecontact', 'admin'),
get_string('coursecontact_desc', 'admin'),
array('editingteacher'));
$this->set_updatedcallback(create_function('',
"cache::make('core', 'coursecontacts')->purge();"));
$this->set_updatedcallback(function (){
cache::make('core', 'coursecontacts')->purge();
});
}
}
......
......@@ -560,8 +560,12 @@ class core_text {
static $callback2 = null ;
if (!$callback1 or !$callback2) {
$callback1 = create_function('$matches', 'return core_text::code2utf8(hexdec($matches[1]));');
$callback2 = create_function('$matches', 'return core_text::code2utf8($matches[1]);');
$callback1 = function($matches) {
return core_text::code2utf8(hexdec($matches[1]));
};
$callback2 = function($matches) {
return core_text::code2utf8($matches[1]);
};
}
$result = (string)$str;
......@@ -600,7 +604,9 @@ class core_text {
if ($dec) {
if (!$callback) {
$callback = create_function('$matches', 'return \'&#\'.(hexdec($matches[1])).\';\';');
$callback = function($matches) {
return '&#' . hexdec($matches[1]) . ';';
};
}
$result = preg_replace_callback('/&#x([0-9a-f]+);/i', $callback, $result);
}
......
......@@ -1779,7 +1779,9 @@ class mysqli_native_moodle_database extends moodle_database {
$rv .= " JOIN (".$selects[$i].") $alias ON ".
join(' AND ',
array_map(
create_function('$a', 'return "'.$falias.'.$a = '.$alias.'.$a";'),
function($a) use ($alias, $falias) {
return $falias . '.' . $a .' = ' . $alias . '.' . $a;
},
preg_split('/,/', $fields))
);
}
......
......@@ -2341,7 +2341,9 @@ require(["core/event", "jquery"], function(Event, $) {
//end of fix
$escapedElementName = preg_replace_callback(
'/[_\[\]-]/',
create_function('$matches', 'return sprintf("_%2x",ord($matches[0]));'),
function($matches) {
return sprintf("_%2x", ord($matches[0]));
},
$elementName);
$valFunc = 'validate_' . $this->_formName . '_' . $escapedElementName . '(ev.target, \''.$escapedElementName.'\')';
......
......@@ -1122,7 +1122,9 @@ function workaround_max_input_vars() {
}
$delim = '&';
$fun = create_function('$p', 'return implode("'.$delim.'", $p);');
$fun = function($p) use ($delim) {
return implode($delim, $p);
};
$chunks = array_map($fun, array_chunk(explode($delim, $str), $max));
// Clear everything from existing $_POST array, otherwise it might be included
......
......@@ -892,7 +892,9 @@ if (strpos($commandline, '-') === false) {
$numswitches = count($switches);
// Fancy way to give a "hyphen" boolean flag to each "switch".
$switches = array_map(create_function('$x', 'return array("str" => $x, "hyphen" => (substr($x, 0, 1) == "-"));'), $switches);
$switches = array_map(function($x) {
return array("str" => $x, "hyphen" => (substr($x, 0, 1) == "-"));
}, $switches);
for ($i = 0; $i < $numswitches; ++$i) {
......
......@@ -289,11 +289,12 @@ class ouwiki_line {
// Note that using a single param for replace only works because all
// the search strings are 6 characters long
$data=str_replace(array('&nbsp;','&#xA0;','&#160;'),' ',$data);
// Tags replaced with equal number of spaces
$data=preg_replace_callback('/<.*?'.'>/',create_function(
'$matches','return preg_replace("/./"," ",$matches[0]);'),$data);
$data = preg_replace_callback('/<.*?'.'>/', function($matches) {
return preg_replace("/./", " ", $matches[0]);
}, $data);
// 2. Analyse string so that each space-separated thing
// is counted as a 'word' (note these may not be real words,
// for instance words may include punctuation at either end)
......@@ -409,9 +410,10 @@ function ouwiki_diff_html_to_lines($content) {
// Get rid of all script, style, object tags (that might contain non-text
// outside tags)
$content=preg_replace_callback(
'^(<script .*?</script>)|(<object .*?</object>)|(<style .*?</style>)^i',create_function(
'$matches','return preg_replace("/./"," ",$matches[0]);'),$content);
'^(<script .*?</script>)|(<object .*?</object>)|(<style .*?</style>)^i', function($matches) {
return preg_replace("/./", " ", $matches[0]);
}, $content);
// Get rid of all ` symbols as we are going to use these for a marker later.
$content=preg_replace('/[`]/',' ',$content);
......@@ -424,8 +426,9 @@ function ouwiki_diff_html_to_lines($content) {
}
$taglist.="<$blocktag>|<\\/$blocktag>";
}
$content=preg_replace_callback('/(('.$taglist.')\s*)+/i',create_function(
'$matches','return "`".preg_replace("/./"," ",substr($matches[0],1));'),$content);
$content = preg_replace_callback('/((' . $taglist . ')\s*)+/i', function($matches) {
return "`" . preg_replace("/./", " ", substr($matches[0], 1));
}, $content);
// Now go through splitting each line
$lines=array(); $index=1;
......@@ -709,8 +712,10 @@ function ouwiki_diff($file1,$file2) {
*/
function ouwiki_diff_add_markers($html,$words,$markerclass,$beforetext,$aftertext) {
// Sort words by start position
usort($words, create_function('$a,$b','return $a->start-$b->start;'));
usort($words, function($a, $b) {
return $a->start - $b->start;
});
// Add marker for each word. We use an odd tag name which will
// be replaced by span later, this for ease of replacing
$spanstart="<ouwiki_diff_add_markers>";
......
......@@ -53,7 +53,9 @@ class qtype_multianswer extends question_type {
// We want an array with question ids as index and the positions as values.
$sequence = array_flip(explode(',', $sequence));
array_walk($sequence, create_function('&$val', '$val++;'));
array_walk($sequence, function(&$val) {
$val++;
});
// If a question is lost, the corresponding index is null
// so this null convention is used to test $question->options->questions
......
......@@ -284,8 +284,10 @@ class core_tag_tag {
$tags = $DB->get_records_select('tag', 'name = :name AND tagcollid ' . $sql, $params, '', $returnfields);
if (count($tags) > 1) {
// Sort in the same order as tag collections.
uasort($tags, create_function('$a,$b', '$tagcolls = core_tag_collection::get_collections(); ' .
'return $tagcolls[$a->tagcollid]->sortorder < $tagcolls[$b->tagcollid]->sortorder ? -1 : 1;'));
$tagcolls = core_tag_collection::get_collections();
uasort($tags, function($a, $b) use ($tagcolls) {
return $tagcolls[$a->tagcollid]->sortorder < $tagcolls[$b->tagcollid]->sortorder ? -1 : 1;
});
}
$rv = array();
foreach ($tags as $id => $tag) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment