Skip to content

Commit

Permalink
MDL-60281 general: function each() is deprecated in PHP7.2
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaglancy committed Oct 16, 2017
1 parent 484b43f commit 33683bc
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 20 deletions.
2 changes: 1 addition & 1 deletion analytics/classes/calculable.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ private function array_merge_recursive_keep_keys() {

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 {
Expand Down
6 changes: 4 additions & 2 deletions lib/moodlelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/webdavlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ function mput($filelist) {

$result = true;

while (list($localpath, $destpath) = each($filelist)) {
foreach ($filelist as $localpath => $destpath) {

$localpath = rtrim($localpath, "/");
$destpath = rtrim($destpath, "/");
Expand Down Expand Up @@ -1011,7 +1011,7 @@ function mget($filelist) {

$result = true;

while (list($remotepath, $localpath) = each($filelist)) {
foreach ($filelist as $remotepath => $localpath) {

$localpath = rtrim($localpath, "/");
$remotepath = rtrim($remotepath, "/");
Expand Down
9 changes: 6 additions & 3 deletions message/tests/api_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -1398,7 +1398,8 @@ public function test_get_message_processor() {
$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);
Expand Down Expand Up @@ -1431,7 +1432,8 @@ public function test_update_processor_status() {
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);
Expand All @@ -1457,7 +1459,8 @@ public function is_user_enabled() {
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);
Expand Down
5 changes: 3 additions & 2 deletions mod/quiz/report/statistics/tests/statistics_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,15 @@ public function qstats_q_fields($fieldname, $values, $multiplier=1) {
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);
Expand Down
2 changes: 1 addition & 1 deletion mod/scorm/aicc.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@
$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));
Expand Down
2 changes: 1 addition & 1 deletion mod/survey/graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@

$options = explode(",",$question->options);

while (list($key,) = each($options)) {
foreach ($options as $key => $unused) {
$buckets1[$key] = 0;
$buckets2[$key] = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion mod/survey/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ function survey_print_multi($question) {

echo "<tr class=\"smalltext\"><th scope=\"row\">$strresponses</th>";
echo "<th scope=\"col\" class=\"hresponse\">". get_string('notyetanswered', 'survey'). "</th>";
while (list ($key, $val) = each ($options)) {
foreach ($options as $key => $val) {
echo "<th scope=\"col\" class=\"hresponse\">$val</th>\n";
}
echo "</tr>\n";
Expand Down
6 changes: 3 additions & 3 deletions mod/wiki/diff/diff_nwiki.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,14 +247,14 @@ function _diag ($xoff, $xlim, $yoff, $ylim, $nchunks) {
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:
Expand Down
9 changes: 6 additions & 3 deletions mod/workshop/allocation/random/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ public function execute(workshop_random_allocator_setting $settings, workshop_al
$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]);
Expand Down Expand Up @@ -324,7 +325,8 @@ protected function add_new_allocations(array $newallocations, array $dataauthors
$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');
}
Expand Down Expand Up @@ -408,7 +410,8 @@ protected function get_unkept_assessments($assessments, $newallocations, $keepse
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;
Expand Down
2 changes: 1 addition & 1 deletion question/classes/statistics/questions/calculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public function calculate($qubaids) {
// 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);
Expand Down

0 comments on commit 33683bc

Please sign in to comment.