From 33683bc80c03029ea45915a78bdeb575ce68b36c Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Mon, 2 Oct 2017 09:15:18 +0800 Subject: [PATCH] MDL-60281 general: function each() is deprecated in PHP7.2 --- analytics/classes/calculable.php | 2 +- lib/moodlelib.php | 6 ++++-- lib/webdavlib.php | 4 ++-- message/tests/api_test.php | 9 ++++++--- mod/quiz/report/statistics/tests/statistics_test.php | 5 +++-- mod/scorm/aicc.php | 2 +- mod/survey/graph.php | 2 +- mod/survey/lib.php | 2 +- mod/wiki/diff/diff_nwiki.php | 6 +++--- mod/workshop/allocation/random/lib.php | 9 ++++++--- question/classes/statistics/questions/calculator.php | 2 +- 11 files changed, 29 insertions(+), 20 deletions(-) diff --git a/analytics/classes/calculable.php b/analytics/classes/calculable.php index 63ea392e5c1..af95120f510 100644 --- a/analytics/classes/calculable.php +++ b/analytics/classes/calculable.php @@ -267,7 +267,7 @@ abstract class calculable { foreach ($arrays as $array) { reset($base); - while (list($key, $value) = each($array)) { + foreach ($array as $key => $value) { if (is_array($value) && !empty($base[$key]) && is_array($base[$key])) { $base[$key] = $this->array_merge_recursive_keep_keys($base[$key], $value); } else { diff --git a/lib/moodlelib.php b/lib/moodlelib.php index d701062b899..d75a07252b9 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -2359,8 +2359,10 @@ function get_user_timezone($tz = 99) { $tz = 99; // Loop while $tz is, empty but not zero, or 99, and there is another timezone is the array. - while (((empty($tz) && !is_numeric($tz)) || $tz == 99) && $next = each($timezones)) { - $tz = $next['value']; + foreach ($timezones as $nextvalue) { + if ((empty($tz) && !is_numeric($tz)) || $tz == 99) { + $tz = $nextvalue; + } } return is_numeric($tz) ? (float) $tz : $tz; } diff --git a/lib/webdavlib.php b/lib/webdavlib.php index f71c61ab762..c1307152233 100644 --- a/lib/webdavlib.php +++ b/lib/webdavlib.php @@ -954,7 +954,7 @@ EOD; $result = true; - while (list($localpath, $destpath) = each($filelist)) { + foreach ($filelist as $localpath => $destpath) { $localpath = rtrim($localpath, "/"); $destpath = rtrim($destpath, "/"); @@ -1011,7 +1011,7 @@ EOD; $result = true; - while (list($remotepath, $localpath) = each($filelist)) { + foreach ($filelist as $remotepath => $localpath) { $localpath = rtrim($localpath, "/"); $remotepath = rtrim($remotepath, "/"); diff --git a/message/tests/api_test.php b/message/tests/api_test.php index 35d15f5f661..7139800c460 100644 --- a/message/tests/api_test.php +++ b/message/tests/api_test.php @@ -1398,7 +1398,8 @@ class core_message_api_testcase extends core_message_messagelib_testcase { $this->markTestSkipped("No message processors found"); } - list($name, $processor) = each($processors); + $name = key($processors); + $processor = current($processors); $testprocessor = \core_message\api::get_message_processor($name); $this->assertEquals($processor->name, $testprocessor->name); $this->assertEquals($processor->enabled, $testprocessor->enabled); @@ -1431,7 +1432,8 @@ class core_message_api_testcase extends core_message_messagelib_testcase { if (empty($processors)) { $this->markTestSkipped("No message processors found"); } - list($name, $testprocessor) = each($processors); + $name = key($processors); + $testprocessor = current($processors); // Enable. \core_message\api::update_processor_status($testprocessor, 1); @@ -1457,7 +1459,8 @@ class core_message_api_testcase extends core_message_messagelib_testcase { if (empty($processors)) { $this->markTestSkipped("No message processors found"); } - list($name, $testprocessor) = each($processors); + $name = key($processors); + $testprocessor = current($processors); // Enable. \core_message\api::update_processor_status($testprocessor, 1); diff --git a/mod/quiz/report/statistics/tests/statistics_test.php b/mod/quiz/report/statistics/tests/statistics_test.php index 3f5e0905615..e67653b8cae 100644 --- a/mod/quiz/report/statistics/tests/statistics_test.php +++ b/mod/quiz/report/statistics/tests/statistics_test.php @@ -154,14 +154,15 @@ class quiz_statistics_question_stats_testcase extends basic_testcase { public function get_fields_from_csv($line) { $line = trim($line); $items = preg_split('!,!', $line); - while (list($key) = each($items)) { + $cnt = count($items); + for ($key = 0; $key < $cnt; $key++) { if ($items[$key]!='') { if ($start = ($items[$key]{0}=='"')) { $items[$key] = substr($items[$key], 1); while (!$end = ($items[$key]{strlen($items[$key])-1}=='"')) { $item = $items[$key]; unset($items[$key]); - list($key) = each($items); + $key++; $items[$key] = $item . ',' . $items[$key]; } $items[$key] = substr($items[$key], 0, strlen($items[$key])-1); diff --git a/mod/scorm/aicc.php b/mod/scorm/aicc.php index 14bcb9904a9..8902fd26577 100644 --- a/mod/scorm/aicc.php +++ b/mod/scorm/aicc.php @@ -217,7 +217,7 @@ if (!empty($command)) { $datamodel['[comments]'] = 'cmi.comments'; $datarows = explode("\r\n", $aiccdata); reset($datarows); - while ((list(, $datarow) = each($datarows)) !== false) { + foreach ($datarows as $datarow) { if (($equal = strpos($datarow, '=')) !== false) { $element = strtolower(trim(substr($datarow, 0, $equal))); $value = trim(substr($datarow, $equal + 1)); diff --git a/mod/survey/graph.php b/mod/survey/graph.php index 7422e7d0b3e..75c0c0e381b 100644 --- a/mod/survey/graph.php +++ b/mod/survey/graph.php @@ -88,7 +88,7 @@ $options = explode(",",$question->options); - while (list($key,) = each($options)) { + foreach ($options as $key => $unused) { $buckets1[$key] = 0; $buckets2[$key] = 0; } diff --git a/mod/survey/lib.php b/mod/survey/lib.php index db773b581cf..6d5f7f4e708 100644 --- a/mod/survey/lib.php +++ b/mod/survey/lib.php @@ -539,7 +539,7 @@ function survey_print_multi($question) { echo "$strresponses"; echo "". get_string('notyetanswered', 'survey'). ""; - while (list ($key, $val) = each ($options)) { + foreach ($options as $key => $val) { echo "$val\n"; } echo "\n"; diff --git a/mod/wiki/diff/diff_nwiki.php b/mod/wiki/diff/diff_nwiki.php index 208a71205c1..6b224d13d03 100644 --- a/mod/wiki/diff/diff_nwiki.php +++ b/mod/wiki/diff/diff_nwiki.php @@ -247,14 +247,14 @@ class _WikiDiffEngine continue; $matches = $ymatches[$line]; reset($matches); - while (list ($junk, $y) = each($matches)) + foreach ($matches as $y) if (empty($this->in_seq[$y])) { $k = $this->_lcs_pos($y); USE_ASSERTS_IN_WIKI && assert($k > 0); $ymids[$k] = $ymids[$k-1]; break; - } - while (list ($junk, $y) = each($matches)) { + } + foreach ($matches as $y) { if ($y > $this->seq[$k-1]) { USE_ASSERTS_IN_WIKI && assert($y < $this->seq[$k]); // Optimization: this is a common case: diff --git a/mod/workshop/allocation/random/lib.php b/mod/workshop/allocation/random/lib.php index ffed33cad42..603cf36e18e 100644 --- a/mod/workshop/allocation/random/lib.php +++ b/mod/workshop/allocation/random/lib.php @@ -126,7 +126,8 @@ class workshop_random_allocator implements workshop_allocator { $allreviewers = $reviewers[0]; $allreviewersreloaded = false; foreach ($newallocations as $newallocation) { - list($reviewerid, $authorid) = each($newallocation); + $reviewerid = key($newallocation); + $authorid = current($newallocation); $a = new stdClass(); if (isset($allreviewers[$reviewerid])) { $a->reviewername = fullname($allreviewers[$reviewerid]); @@ -324,7 +325,8 @@ class workshop_random_allocator implements workshop_allocator { $submissions = $this->workshop->get_submissions($authorids); $submissions = $this->index_submissions_by_authors($submissions); foreach ($newallocations as $newallocation) { - list($reviewerid, $authorid) = each($newallocation); + $reviewerid = key($newallocation); + $authorid = current($newallocation); if (!isset($submissions[$authorid])) { throw new moodle_exception('unabletoallocateauthorwithoutsubmission', 'workshop'); } @@ -408,7 +410,8 @@ class workshop_random_allocator implements workshop_allocator { continue; } foreach ($newallocations as $newallocation) { - list($nrid, $naid) = each($newallocation); + $nrid = key($newallocation); + $naid = current($newallocation); if (array($arid, $aaid) == array($nrid, $naid)) { // re-allocation found - let us continue with the next assessment $keepids[$assessmentid] = null; diff --git a/question/classes/statistics/questions/calculator.php b/question/classes/statistics/questions/calculator.php index 567e6e9683f..4f0f2853fcb 100644 --- a/question/classes/statistics/questions/calculator.php +++ b/question/classes/statistics/questions/calculator.php @@ -187,7 +187,7 @@ class calculator { // foreach ($this->questions as $qid => $question). $slots = $this->stats->get_all_slots(); $this->progress->start_progress('', count($slots), 1); - while (list(, $slot) = each($slots)) { + foreach ($slots as $slot) { $this->stats->for_slot($slot)->sort_variants(); $this->progress->increment_progress(); $nextslot = current($slots);