From 75c440c4bd3ede1ab58e79579c4c0c14cf1f89c9 Mon Sep 17 00:00:00 2001 From: Basemaster Date: Thu, 22 Aug 2024 13:18:34 +0300 Subject: [PATCH] PHP8 change each() to foreach() --- src/Snoopy.php | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/Snoopy.php b/src/Snoopy.php index 9bfdaf7..f3405a7 100644 --- a/src/Snoopy.php +++ b/src/Snoopy.php @@ -195,7 +195,8 @@ class Snoopy $frameurls = $this->_frameurls; $this->_frameurls = []; - while (list(, $frameurl) = each($frameurls)) + //while (list(, $frameurl) = each($frameurls)) + foreach ($frameurls as $frameurl) { if ($this->_framedepth < $this->maxframes) { @@ -327,7 +328,8 @@ class Snoopy $frameurls = $this->_frameurls; $this->_frameurls = []; - while (list(, $frameurl) = each($frameurls)) + //while (list(, $frameurl) = each($frameurls)) + foreach ($frameurls as $frameurl) { if ($this->_framedepth < $this->maxframes) { @@ -603,7 +605,8 @@ class Snoopy // catenate the non-empty matches from the conditional subpattern - while (list($key, $val) = each($links[2])) + //while (list($key, $val) = each($links[2])) + foreach ($links[2] as $key => $val) { if (!empty($val)) { @@ -611,7 +614,8 @@ class Snoopy } } - while (list($key, $val) = each($links[3])) + //while (list($key, $val) = each($links[3])) + foreach ($links[3] as $key => $val) { if (!empty($val)) { @@ -833,7 +837,8 @@ class Snoopy { $this->rawheaders = (array) $this->rawheaders; } - while (list($headerKey, $headerVal) = each($this->rawheaders)) + //while (list($headerKey, $headerVal) = each($this->rawheaders)) + foreach ($this->rawheaders as $headerKey => $headerVal) { $headers .= $headerKey . ": " . $headerVal . "\r\n"; } @@ -1165,11 +1170,13 @@ class Snoopy { case "application/x-www-form-urlencoded": reset($formvars); - while (list($key, $val) = each($formvars)) + //while (list($key, $val) = each($formvars)) + foreach ($formvars as $key => $val) { if (is_array($val) || is_object($val)) { - while (list($cur_key, $cur_val) = each($val)) + //while (list($cur_key, $cur_val) = each($val)) + foreach ($val as $cur_key => $cur_val) { $postdata .= urlencode($key) . "[]=" . urlencode($cur_val) . "&"; } @@ -1185,11 +1192,13 @@ class Snoopy $this->_mime_boundary = "Snoopy" . md5(uniqid(microtime())); reset($formvars); - while (list($key, $val) = each($formvars)) + //while (list($key, $val) = each($formvars)) + foreach ($formvars as $key => $val) { if (is_array($val) || is_object($val)) { - while (list($cur_key, $cur_val) = each($val)) + //while (list($cur_key, $cur_val) = each($val)) + foreach ($val as $cur_key => $cur_val) { $postdata .= "--" . $this->_mime_boundary . "\r\n"; $postdata .= "Content-Disposition: form-data; name=\"$key\[\]\"\r\n\r\n"; @@ -1205,10 +1214,12 @@ class Snoopy } reset($formfiles); - while (list($field_name, $file_names) = each($formfiles)) + //while (list($field_name, $file_names) = each($formfiles)) + foreach ($formfiles as $field_name => $file_name) { settype($file_names, "array"); - while (list(, $file_name) = each($file_names)) + //while (list(, $file_name) = each($file_names)) + foreach ($file_names as $file_name) { if (!is_readable($file_name)) {