0
votes

I am new to OOP and having hard time trying to echo value of SMSMessageBody in code below:

stdClass Object
(
    [GetSentMessagesResult] => stdClass Object
        (
            [SentMessage] => Array
                (
                [0] => stdClass Object
                    (
                        [ID] => 6567960
                        [LineNumber] => 30004554552584
                        [SMSMessageBody] => Lorem ipsum 
                        [MobileNo] => 9122588874
                        ....

I have seen these posts in stackoverflow:

So I tried the following code:

echo    $client->GetSentMessagesResult->SentMessage[0]->SMSMessageBody; 

But got this Notice:

Notice: Trying to get property of non-object in C:\xampp\htdocs\banks\newbank\sentsms.php on line 18

Any help would be appreciated.

1
Firstly, make sure you are trying to use the correct variable. Then, try to figure out where it starts to give you the error, is it at $client->GetSentMessagesResult->SentMessage or maybe at $client->GetSentMessagesResult?* - FirstOne
what is the output of echo "<pre/>";print_r($client);? - Anant Kumar Singh
@Anant the output of echo "<pre/>";print_r($client); is SoapClient Object ( [_soap_version] => 1 [sdl] => Resource id #10 ) - Ali Kashi
@FirstOne how can I test the level of error? - Ali Kashi
@AliKashi, my comment is already showing you that. You keep going up in the tree to find out if it stops giving you that error. - FirstOne

1 Answers

0
votes

This is not an object, it's a string, so please check using var_dump funtion like as follows: var_dump($client);

It's showing a string then you can not access with this code:

echo $client->GetSentMessagesResult -> SentMessage[0] -> SMSMessageBody;