MDL-58546 libraries: Patch ADOdb for PHP 7.2 compat
authorMarina Glancy <marina@moodle.com>
Tue, 3 Oct 2017 07:52:18 +0000 (15:52 +0800)
committerMarina Glancy <marina@moodle.com>
Tue, 3 Oct 2017 07:52:18 +0000 (15:52 +0800)
lib/adodb/adodb-datadict.inc.php
lib/adodb/adodb-error.inc.php
lib/adodb/adodb.inc.php
lib/adodb/drivers/adodb-ado.inc.php
lib/adodb/drivers/adodb-ado5.inc.php
lib/adodb/drivers/adodb-text.inc.php
lib/adodb/readme_moodle.txt
lib/adodb/toexport.inc.php

index b15a80e..b2a0837 100644 (file)
@@ -520,7 +520,7 @@ class ADODB_DataDict {
                        list($lines,$pkey,$idxs) = $this->_GenFields($flds);
                        // genfields can return FALSE at times
                        if ($lines == null) $lines = array();
-                       list(,$first) = each($lines);
+                       $first  = current($lines);
                        list(,$column_def) = preg_split("/[\t ]+/",$first,2);
                }
                return array(sprintf($this->renameColumn,$tabname,$this->NameQuote($oldcolumn),$this->NameQuote($newcolumn),$column_def));
index d42a06a..18f944b 100644 (file)
@@ -111,7 +111,7 @@ function adodb_error_pg($errormsg)
                        'could not serialize access due to'   => DB_ERROR_SERIALIZATION_FAILURE
                );
        reset($error_regexps);
-       while (list($regexp,$code) = each($error_regexps)) {
+       foreach ($error_regexps as $regexp => $code) {
                if (preg_match("/$regexp/mi", $errormsg)) {
                        return $code;
                }
index 019cdda..b01b0af 100644 (file)
@@ -1164,8 +1164,7 @@ if (!defined('_ADODB_LAYER')) {
 
                                foreach($inputarr as $arr) {
                                        $sql = ''; $i = 0;
-                                       //Use each() instead of foreach to reduce memory usage -mikefedyk
-                                       while(list(, $v) = each($arr)) {
+                                       foreach ($arr as $v) {
                                                $sql .= $sqlarr[$i];
                                                // from Ron Baldwin <ron.baldwin#sourceprose.com>
                                                // Only quote string types
index 449cdd0..04b7dc8 100644 (file)
@@ -225,7 +225,7 @@ class ADODB_ado extends ADOConnection {
 
       // Map by http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdmthcreateparam.asp
       // Check issue http://bugs.php.net/bug.php?id=40664 !!!
-                       while(list(, $val) = each($inputarr)) {
+                       foreach ($inputarr as $val) {
                                $type = gettype($val);
                                $len=strlen($val);
                                if ($type == 'boolean')
index 21df32f..73c4b50 100644 (file)
@@ -248,7 +248,7 @@ class ADODB_ado extends ADOConnection {
                        $oCmd->CommandText = $sql;
                        $oCmd->CommandType = 1;
 
-                       while(list(, $val) = each($inputarr)) {
+                       foreach ($inputarr as $val) {
                                $type = gettype($val);
                                $len=strlen($val);
                                if ($type == 'boolean')
index 347167a..8844d20 100644 (file)
@@ -209,7 +209,7 @@ class ADODB_text extends ADOConnection {
                        $where_arr = array();
 
                        reset($this->_origarray);
-                       while (list($k_arr,$arr) = each($this->_origarray)) {
+                       foreach ($this->_origarray as $arr) {
 
                                if ($i == 0 && $this->_skiprow1)
                                        $where_arr[] = $arr;
@@ -247,7 +247,7 @@ class ADODB_text extends ADOConnection {
                                $i = 0;
                                $n = '';
                                reset($this->_colnames);
-                               while (list($k_n,$n) = each($this->_colnames)) {
+                               foreach ($this->_colnames as $n) {
 
                                        if ($col == strtoupper(trim($n))) break;
                                        $i += 1;
@@ -302,7 +302,7 @@ class ADODB_text extends ADOConnection {
                if ($at == 0) {
                        $i = 0;
                        reset($projnames);
-                       while (list($k_n,$n) = each($projnames)) {
+                       foreach ($projnames as $n) {
                                if (strtoupper(trim($n)) == $col) {
                                        $at = $i+1;
                                        break;
index 22c5935..00ff240 100644 (file)
@@ -30,5 +30,7 @@ Our changes:
  * Removed random seed initialization from lib/adodb/adodb.inc.php:216 (see 038f546 and MDL-41198).
  * MDL-52286 Added muting erros in ADORecordSet::__destruct().
    Check if fixed upstream during the next upgrade and remove this note. (8638b3f1441d4b928)
+ * MDL-58546 replaced each() with foreach for PHP 7.2 compatibility.
+   pull request upstream: https://github.com/ADOdb/ADOdb/pull/373
 
-skodak, iarenaza, moodler, stronk7, abgreeve, lameze, ankitagarwal
+skodak, iarenaza, moodler, stronk7, abgreeve, lameze, ankitagarwal, marinaglancy
index 94c394b..6e3d491 100644 (file)
@@ -77,7 +77,7 @@ function _adodb_export(&$rs,$sep,$sepreplace,$fp=false,$addtitles=true,$quote =
                reset($fieldTypes);
                $i = 0;
                $elements = array();
-               while(list(,$o) = each($fieldTypes)) {
+               foreach ($fieldTypes as $o) {
 
                        $v = ($o) ? $o->name : 'Field'.($i++);
                        if ($escquote) $v = str_replace($quote,$escquotequote,$v);