php-7.2 fix - 'each' has been deprecated
authorSjon Hortensius <sjon@hortensius.net>
Wed, 17 Jul 2019 08:22:20 +0000 (10:22 +0200)
committerRobert Treat <rob@xzilla.net>
Wed, 17 Jul 2019 15:37:09 +0000 (11:37 -0400)
classes/database/ADODB_base.php
dataexport.php
libraries/adodb/adodb-datadict.inc.php
libraries/adodb/adodb-error.inc.php
libraries/adodb/adodb.inc.php
libraries/adodb/toexport.inc.php

index 9e597f0fb615a8d595be336ac51eaa89d76fd726..08a832f122e1c71226b387c568f36a9e6dce19b8 100644 (file)
@@ -58,10 +58,7 @@ class ADODB_base {
         * @return The cleaned array
         */
        function arrayClean(&$arr) {
-               reset($arr);
-               while(list($k, $v) = each($arr))
-                       $arr[$k] = addslashes($v);
-               return $arr;
+               return $arr = array_map('addslashes', $arr);
        }
        
        /**
@@ -132,8 +129,6 @@ class ADODB_base {
        function delete($table, $conditions, $schema = '') {
                $this->fieldClean($table);
 
-               reset($conditions);
-
                if (!empty($schema)) {
                        $this->fieldClean($schema);
                        $schema = "\"{$schema}\".";
@@ -141,7 +136,7 @@ class ADODB_base {
 
                // Build clause
                $sql = '';
-               while(list($key, $value) = each($conditions)) {
+               foreach($conditions as $key => $value) {
                        $this->clean($key);
                        $this->clean($value);
                        if ($sql) $sql .= " AND \"{$key}\"='{$value}'";
@@ -220,23 +215,20 @@ class ADODB_base {
                $whereClause = '';
 
                // Populate the syntax arrays
-               reset($vars);
-               while(list($key, $value) = each($vars)) {
+               foreach($vars as $key => $value) {
                        $this->fieldClean($key);
                        $this->clean($value);
                        if ($setClause) $setClause .= ", \"{$key}\"='{$value}'";
                        else $setClause = "UPDATE \"{$table}\" SET \"{$key}\"='{$value}'";
                }
 
-               reset($nulls);
-               while(list(, $value) = each($nulls)) {
+               foreach($nulls as $value) {
                        $this->fieldClean($value);
                        if ($setClause) $setClause .= ", \"{$value}\"=NULL";
                        else $setClause = "UPDATE \"{$table}\" SET \"{$value}\"=NULL";
                }
 
-               reset($where);
-               while(list($key, $value) = each($where)) {
+               foreach($where as $key => $value) {
                        $this->fieldClean($key);
                        $this->clean($value);
                        if ($whereClause) $whereClause .= " AND \"{$key}\"='{$value}'";
index 84db24f872ad7b3397b52a231118ab420f91b681..0d245f773c0ed0d61dd8cc58f23b98a76fee731c 100644 (file)
                                echo " FROM stdin;\n";
                                while (!$rs->EOF) {
                                        $first = true;
-                                       while(list($k, $v) = each($rs->fields)) {
+                                       foreach ($rs->fields as $k => $v) {
                                                // Escape value
                                                $v = $data->escapeBytea($v);
                                                
index 69060c5cef6b794ea91263206f8c92dfb26539f5..b62f1ae0500a7921b4c45becfc9afa0e0dd71fa0 100644 (file)
@@ -518,7 +518,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 = reset($lines);
                        list(,$column_def) = preg_split("/[\t ]+/",$first,2);
                }
                return array(sprintf($this->renameColumn,$tabname,$this->NameQuote($oldcolumn),$this->NameQuote($newcolumn),$column_def));
index 6ec614d2c19ae9ab88987587da6d93b67703b9e9..c6be5b5546b73b48ef720bad576c85f9127d8322 100755 (executable)
@@ -102,8 +102,7 @@ function adodb_error_pg($errormsg)
                        '/Relation [\"\'].*[\"\'] already exists|Cannot insert a duplicate key into (a )?unique index.*|duplicate key.*violates unique constraint/i'     
                                 => DB_ERROR_ALREADY_EXISTS
         );
-       reset($error_regexps);
-    while (list($regexp,$code) = each($error_regexps)) {
+       foreach($error_regexps as $regexp => $code) {
         if (preg_match($regexp, $errormsg)) {
             return $code;
         }
index 8cfb3887c810fcd6e72118c16fa1f88802559e2b..5b0704c1b633dc9e39a7e76849ad164fb9fa8688 100755 (executable)
                                if (!$array_2d) $inputarr = array($inputarr);
                                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 6975b51a446d567bcf6466eec924fcc65b371309..f2bde63fa5dbcb23e1455ddee764bace26570319 100644 (file)
@@ -72,10 +72,8 @@ function _adodb_export(&$rs,$sep,$sepreplace,$fp=false,$addtitles=true,$quote =
        
        if ($addtitles) {
                $fieldTypes = $rs->FieldTypesArray();
-               reset($fieldTypes);
                $i = 0;
-               while(list(,$o) = each($fieldTypes)) {
-               
+               foreach($fieldTypes as $o) {
                        $v = ($o) ? $o->name : 'Field'.($i++);
                        if ($escquote) $v = str_replace($quote,$escquotequote,$v);
                        $v = strip_tags(str_replace("\n", $replaceNewLine, str_replace("\r\n",$replaceNewLine,str_replace($sep,$sepreplace,$v))));