tags:

views:

18

answers:

2

I'm actually working with SOAP at the moment, and annoyingly the response name varies depending on the method I call. For example, one method will respond with..

$response->SendOrderResult

whilst another responds with

$response->GetOrdersStateResult

Is there a way of referring to the value without knowing the name? ie something like $response->*Result

A: 

No, this is not possible, you should be able to figure out what method to call by analyzing your code and call the required method afterwords:

if (this condition)
{
  $response->SendOrderResult();
}
else
{
  $response->GetOrdersStateResult();
}

Another possibility is to use the get_class_methods function.

$class_methods = get_class_methods(new myclass());

foreach ($class_methods as $method_name)
{
    echo "$method_name\n";
}
Sarfraz
A: 

you can write a little function for that (assuming that $response is of type stdClass):

function extractResult($response) {
    foreach ($response as $attribute_name => $attribute_value) {
        if (strtolower(substr($attribute_name, -6)) == 'result')
            return $attribute_value;
    }
}

You can then call it via

$result = extractResult($response);

Note: There might be some cases in which the function will not work, i.e. if the resulting attribute name does not end with Result.

Cassy