Skip to content

Commit

Permalink
Remove usages of 'each', as it is deprecated in php 7.2
Browse files Browse the repository at this point in the history
  • Loading branch information
gggeek committed Sep 3, 2017
1 parent 509dee3 commit ac735cf
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 25 deletions.
2 changes: 1 addition & 1 deletion demo/server/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
17 changes: 7 additions & 10 deletions lib/xmlrpc.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<value>' . $this->serializedata($typ, $val) . "</value>\n";
//}
Expand All @@ -106,29 +106,26 @@ 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();
}
}

// 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;
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/Encoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public function decode($xmlrpcVal, $options = array())
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;
Expand Down Expand Up @@ -183,8 +183,7 @@ public function encode($phpVal, $options = array())
$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);
Expand Down
2 changes: 1 addition & 1 deletion src/Helper/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function parseResponseHeaders(&$data, $headersProcessed = false, $debug=0
}
// 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) {
Expand Down
15 changes: 7 additions & 8 deletions src/Value.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,8 @@ protected function serializedata($typ, $val, $charsetEncoding = '')
*/
public function serialize($charsetEncoding = '')
{
reset($this->me);
list($typ, $val) = each($this->me);
$val = reset($this->me);
$typ = key($this->me);

return '<value>' . $this->serializedata($typ, $val, $charsetEncoding) . "</value>\n";
}
Expand Down Expand Up @@ -394,8 +394,7 @@ public function structeach()
*/
public function scalarval()
{
reset($this->me);
list(, $b) = each($this->me);
$b = reset($this->me);

return $b;
}
Expand All @@ -410,7 +409,7 @@ public function scalarval()
public function scalartyp()
{
reset($this->me);
list($a,) = each($this->me);
$a = key($this->me);
if ($a == static::$xmlrpcI4) {
$a = static::$xmlrpcInt;
}
Expand Down Expand Up @@ -525,7 +524,7 @@ public function offsetSet($offset, $value) {
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('');
}
Expand Down Expand Up @@ -575,8 +574,8 @@ public function offsetGet($offset) {
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?
Expand Down
2 changes: 1 addition & 1 deletion tests/3LocalhostTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ public function testCountEntities()
$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'];
}
Expand Down

0 comments on commit ac735cf

Please sign in to comment.