1

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 / 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

2
  • sorry, forgot the dollar sign if that makes a difference? Commented Mar 29, 2010 at 12:51
  • yes, it makes a difference, I just deleted my answer and my comment. $variable != constant. Commented Mar 29, 2010 at 12:57

2 Answers 2

2

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;
Sign up to request clarification or add additional context in comments.

Comments

0

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;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.