Mombu the Php Forum

Go Back   Mombu the Php Forum > Php > SoapClient and arrays
User Name
Password
REGISTER NOW! Mark Forums Read




Reply Bookmark and Share
1 21st November 19:11
lehmann
External User
 
Posts: 1
Default SoapClient and arrays



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) "FGLHRQXVDQJXQAWBCGJWNCQKTOYFGGMJSHYQELJPSABDGUNZW BEA"
["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) "FGLHRQXWDWKHQPWRDCKSNYRGUKZBHCNFSXZHENMTVKEHJZQPY Z"
["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
  Reply With Quote


 


2 21st November 19:11
mrclay
External User
 
Posts: 1
Default SoapClient and arrays



It's an object, so have you tried this?
echo $response->key;

Steve
  Reply With Quote
3 21st November 19:11
aschwin
External User
 
Posts: 1
Default SoapClient and arrays


What about $response->key ??? What does that give? It seems to me, that
$response->key will be a public property of the stdClass?
--

Aschwin Wesselius

/'What you would like to be done to you, do that to the other....'/
  Reply With Quote
4 21st November 22:52
lehmann
External User
 
Posts: 1
Default SoapClient and arrays


Hello,


thanks, this works fine.

Regards
Marten
  Reply With Quote
Reply


Thread Tools
Display Modes


Some other forums that might be of your interest : Php 5 forum, Apache forum, Iis forum, Functions forum, Classes forum, Librarys forum, Bugs forum, Postgres forum, Mysql forum, Paradox forum, Ms sql forum, Configurations forum, Php.ini forum, Problems forum, Scripting forum, Css forum, General forums, Off-topic talk, Links, Extra forums, Php


Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666