开发者

PHP Error, is it resolvable, or a language bug?

Given the following code

$c= new SoapClient('http://www.webservicex.net/CurrencyConvertor.asmx?WSDL');

$usa = "USD";
$eng = "GBP";

doing a __getTypes on the client gives me

Array ( [0] => struct ConversionRate { Currency FromCurrency; Currency ToCurrency; } [1] => string Currency [2] => struct ConversionRateResponse { double ConversionRateResult; } )

if i then do

$calculation = $c->ConversionRate($usa, $eng);

and print calculation i get an error about

Catchable fatal error: Object of class stdClass could not be converted to string

Is there a specific way i should be printing this out, or i it a bug, from researching开发者_StackOverflow / googling many people seem to have a problem but i cant find a suitbale solution, other than downgrading php, which isnt a solution for me as i am doing this as homework and its running off of a college server


I'm guessing the return type from that function is not a string (or anything with __toString defined). Normally instances of stdClass will have one or more properties which will be of use to you.

Try doing something like:

print_r($calculation)

That should tell you what the object has on it, and what it is you might want to do with it. I'd guess you'd want to be printing some property off there along the lines of (example):

echo $calculation->result;


Try passing the parameters as an array:

$parameters = array('FromCurrency' => "USD",
     'ToCurrency' => "GBP");
$calculation = $soapClient->ConversionRate($parameters)
var_dump($calculation);

var_dump() could highlight that your result is an object and the double could be a member of that object. Example:

$calculation->ConversionRateResult;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜