From ac735cf96eb914759f7e7595630857254b599783 Mon Sep 17 00:00:00 2001 From: gggeek Date: Sun, 3 Sep 2017 20:11:32 +0100 Subject: [PATCH] Remove usages of 'each', as it is deprecated in php 7.2 --- demo/server/server.php | 2 +- lib/xmlrpc.inc | 17 +++++++---------- src/Encoder.php | 7 +++---- src/Helper/Http.php | 2 +- src/Value.php | 15 +++++++-------- tests/3LocalhostTest.php | 2 +- 6 files changed, 20 insertions(+), 25 deletions(-) diff --git a/demo/server/server.php b/demo/server/server.php index b18cf46..1af2554 100644 --- a/demo/server/server.php +++ b/demo/server/server.php @@ -351,7 +351,7 @@ function ageSorter($req) // hack, must make global as uksort() won't // allow us to pass any other auxiliary information uksort($agesorter_arr, 'agesorter_compare'); - while (list($key, $val) = each($agesorter_arr)) { + foreach($agesorter_arr as $key => $val) { // recreate each struct element $v[] = new Value( array( diff --git a/lib/xmlrpc.inc b/lib/xmlrpc.inc index 28b47d3..74ff080 100644 --- a/lib/xmlrpc.inc +++ b/lib/xmlrpc.inc @@ -92,8 +92,8 @@ class xmlrpcval extends PhpXmlRpc\Value //if (is_object($o) && (get_class($o) == 'xmlrpcval' || is_subclass_of($o, 'xmlrpcval'))) //{ $ar = $o->me; - reset($ar); - list($typ, $val) = each($ar); + $val = reset($ar); + $typ = key($ar); return '' . $this->serializedata($typ, $val) . "\n"; //} @@ -106,16 +106,15 @@ class xmlrpcval extends PhpXmlRpc\Value public function getval() { // UNSTABLE - reset($this->me); - list($a, $b) = each($this->me); + $b = reset($this->me); + $a = key($this->me); // contributed by I Sofer, 2001-03-24 // add support for nested arrays to scalarval // i've created a new method here, so as to // preserve back compatibility if (is_array($b)) { - @reset($b); - while (list($id, $cont) = @each($b)) { + foreach($b as $id => $cont) { $b[$id] = $cont->scalarval(); } } @@ -123,12 +122,10 @@ class xmlrpcval extends PhpXmlRpc\Value // add support for structures directly encoding php objects if (is_object($b)) { $t = get_object_vars($b); - @reset($t); - while (list($id, $cont) = @each($t)) { + foreach($t as $id => $cont) { { $t[$id] = $cont->scalarval(); } - @reset($t); - while (list($id, $cont) = @each($t)) { + foreach($t as $id => $cont) { @$b->$id = $cont; } } diff --git a/src/Encoder.php b/src/Encoder.php index dfec15d..735c3ed 100644 --- a/src/Encoder.php +++ b/src/Encoder.php @@ -36,8 +36,8 @@ class Encoder switch ($xmlrpcVal->kindOf()) { case 'scalar': if (in_array('extension_api', $options)) { - reset($xmlrpcVal->me); - list($typ, $val) = each($xmlrpcVal->me); + $val = reset($xmlrpcVal->me); + $typ = key($xmlrpcVal->me); switch ($typ) { case 'dateTime.iso8601': $xmlrpcVal->scalar = $val; @@ -183,8 +183,7 @@ class Encoder $xmlrpcVal = new Value($phpVal->format('Ymd\TH:i:s'), Value::$xmlrpcStruct); } else { $arr = array(); - reset($phpVal); - while (list($k, $v) = each($phpVal)) { + foreach($phpVal as $k => $v) { $arr[$k] = $this->encode($v, $options); } $xmlrpcVal = new Value($arr, Value::$xmlrpcStruct); diff --git a/src/Helper/Http.php b/src/Helper/Http.php index 2faf583..03a1ab6 100644 --- a/src/Helper/Http.php +++ b/src/Helper/Http.php @@ -133,7 +133,7 @@ class Http } // be tolerant to line endings, and extra empty lines $ar = preg_split("/\r?\n/", trim(substr($data, 0, $pos))); - while (list(, $line) = @each($ar)) { + foreach($ar as $line) { // take care of multi-line headers and cookies $arr = explode(':', $line, 2); if (count($arr) > 1) { diff --git a/src/Value.php b/src/Value.php index 97852b0..8747e69 100644 --- a/src/Value.php +++ b/src/Value.php @@ -329,8 +329,8 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess */ public function serialize($charsetEncoding = '') { - reset($this->me); - list($typ, $val) = each($this->me); + $val = reset($this->me); + $typ = key($this->me); return '' . $this->serializedata($typ, $val, $charsetEncoding) . "\n"; } @@ -394,8 +394,7 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess */ public function scalarval() { - reset($this->me); - list(, $b) = each($this->me); + $b = reset($this->me); return $b; } @@ -410,7 +409,7 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess public function scalartyp() { reset($this->me); - list($a,) = each($this->me); + $a = key($this->me); if ($a == static::$xmlrpcI4) { $a = static::$xmlrpcInt; } @@ -525,7 +524,7 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess case 1: // todo: handle i4 vs int reset($this->me); - list($type,) = each($this->me); + $type = key($this->me); if ($type != $offset) { throw new \Exception(''); } @@ -575,8 +574,8 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess return isset($this->me['array'][$offset]) ? $this->me['array'][$offset] : null; case 1: // on bad type: null or exception? - reset($this->me); - list($type, $value) = each($this->me); + $value = reset($this->me); + $type = key($this->me); return $type == $offset ? $value : null; default: // return null or exception? diff --git a/tests/3LocalhostTest.php b/tests/3LocalhostTest.php index 0290dbf..118f10b 100644 --- a/tests/3LocalhostTest.php +++ b/tests/3LocalhostTest.php @@ -411,7 +411,7 @@ And turned it into nylon'; $got = ''; $expected = '37210'; $expect_array = array('ctLeftAngleBrackets', 'ctRightAngleBrackets', 'ctAmpersands', 'ctApostrophes', 'ctQuotes'); - while (list(, $val) = each($expect_array)) { + foreach($expect_array as $val) { $b = $v->structmem($val); $got .= $b->me['int']; } -- 2.43.0