SoapClient and arrays

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

I'm calling a webservice that is described by a WSDL-URL using the PHP-builtin Soap client. This works fine in general. But although the response is received correct, the variable type is wrong.

According to the WSDL file, the response is defined like this:

<s:element name="SaveResponse">
  <s:complexType>
    <s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="SaveResult" type="s:boolean" />
      <s:element minOccurs="0" maxOccurs="1" name="key" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="messages" type="tns:ArrayOfMessage" />
    </s:sequence>
  </s:complexType>
</s:element>

This pice of code:

print gettype($response). "\n";
var_dump($response);
print $response["key"]. "\n";

returns this:

object
object(stdClass)#2 (3) {
  ["SaveResult"]=>
  bool(true)
  ["key"]=>
  string(52) "FGLHRQXVDQJXQAWBCGJWNCQKTOYFGGMJSHYQELJPSABDGUNZWBEA"
  ["messages"]=>
  object(stdClass)#3 (0) {
  }
}

Fatal error: Cannot use object of type stdClass as array in /whatever/soap.php on line 26

You can see the structure of an associative array. But PHP doesn't treat it as an array. Now with the following code, it works fine:

settype($response, "array");
print gettype($response). "\n";
var_dump($response);
print $response["key"]. "\n";

This returns:

array
array(3) {
  ["SaveResult"]=>
  bool(true)
  ["key"]=>
  string(50) "FGLHRQXWDWKHQPWRDCKSNYRGUKZBHCNFSXZHENMTVKEHJZQPYZ"
  ["messages"]=>
  object(stdClass)#3 (0) {
  }
}
FGLHRQXWDWKHQPWRDCKSNYRGUKZBHCNFSXZHENMTVKEHJZQPYZ

But it seems a bit unhandy and a workaround, if I have to the settype() thing each time I call a webservice. Is there a simpler way?

Regards
Marten

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux