Welcome Guest, Not a member yet? Register   Sign In
XML-RPC Empty Return Structs
#1

[eluser]Elliot Haughin[/eluser]
Under 1.6.2, when using the XML-RPC Client library, an error occurs when handling 'empty' struct's.

libraries/Xmlrpc.php Line 1326:

Code:
switch($this->xmlrpcTypes[$typ])
{

    case 3:

        // struct

        $rs .= "<struct>\n";

        reset($val);

        while(list($key2, $val2) = each($val))

        {

            $rs .= "<member>\n<name>{$key2}</name>\n";

            $rs .= $this->serializeval($val2);

            $rs .= "</member>\n";

        }

        $rs .= '</struct>';

    break;

Produces:

Quote:A PHP Error was encountered

Severity: Warning

Message: reset() [function.reset]: Passed variable is not an array or object

Filename: libraries/Xmlrpc.php

Line Number: 1331
A PHP Error was encountered

Severity: Warning

Message: Variable passed to each() is not an array or object

Filename: libraries/Xmlrpc.php

Line Number: 1332


The library doesn't take into account that the struct could be empty...
should be:

Code:
switch($this->xmlrpcTypes[$typ])
{

    case 3:

        // struct

        $rs .= "<struct>\n";
        
        if ( !empty($val) )
        {

            reset($val);

            while(list($key2, $val2) = each($val))

            {

                $rs .= "<member>\n<name>{$key2}</name>\n";

                $rs .= $this->serializeval($val2);

                $rs .= "</member>\n";

            }
        }

        $rs .= '</struct>';

    break;

Maybe this isn't a bug... but just thought you might want to check it out.




Theme © iAndrew 2016 - Forum software by © MyBB