Undefined property: stdClass::$0 Twitter API returned collection

Viewed 255

I am having trouble accessing property of a stdClass Object returned from Twitter API collection. Here is part of the code

$result = $cb->statuses_userTimeline([
   'count' => '3'
]);

echo $result->{0}->text;

The result of the echo command above is Undefined property: stdClass::$0

Trying to get property of non-object in echo $result->{0}->text

Here is part of the var_dump($result) output

stdClass Object
(
    [0] => stdClass Object
        (
            [created_at] => Sun ........
            [id] => 9..........37088
            [id_str] => 9..........37088
            [text] => This is text
            [truncated] => 
            [entities] => stdClass Object

I have no idea what is wrong there. Can anyone kindly help please.

1 Answers

Try typecasting the object to an array instead, like:

$result = (array)$cb->statuses_userTimeline([
   'count' => '3'
]);

echo $result[0]->text;
Related