Search code examples
phpsoapwsdl

PHP How to Handle SOAP Responce


I need to check the result of an if statement

$client = new SoapClient("http://example.com/message.asmx?wsdl");
/* Set your parameters for the request */
$params = array(
    "recepient" => "$recipient",
    "short_message" => "$text",
    "message_id" => $smsid,
    "deadline" => $deadline,
    "user_id" => "$userid"
);

/* Invoke webservice method with your parameters, in this case: Function1 */
$response = $client->__soapCall("Standard", array($params));

var_dump($response);

I get responce

object(stdClass)#3 (1) { ["StandardResult"]=> bool(true) }

How can I write an if statement to check if StandardResult has value of true.
Also if I get StandardResult as 'SENT' how could I use/get that?
I basically want to:

if ($responce['StandardResult'] == true) {
    echo "Expectancy is met";
}

or

if ($responce['StandardResult'] == 'SENT') {
    echo "Expectancy is met";
}

Solution

  • It is a object, so you can access like property access.

    if ($response->StandardResult) {
    }