Ali Kashi
Ali Kashi

Reputation: 9

How do I echo the data within this nested stdClass Object?

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.

Upvotes: 0

Views: 722

Answers (1)

msrajwat298
msrajwat298

Reputation: 493

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;

Upvotes: 0

Related Questions