Accessing data in an object
Posted: Thu Mar 05, 2009 5:10 pm
I am fairly well versed in PHP, but don't have all that much experience with objects. I am using a class for Twitter that I found and when requesting tweets for a particular user it returns an object named $myObject with the following structure:
I cannot figure out how to access the values in this object. $myObject[0]['text'] does not work, $myObject->0['text'] does not work, $myObject->0->text does not work, foreach($myObject as $tweet) does not work, foreach($myObject as $key=>$tweet) does not work. Nothing I've tried works. What am I missing?
The object is like an array of objects, I only included the first element here, but there is "[1] => stdClass Object" and so on after this one.
Code: Select all
stdClass Object
(
[0] => stdClass Object
(
[text] => Signing In Back to Normal http://tinyurl.com/agklal
[user] => stdClass Object
(
[description] => Always wondering what everyone's doing.
[profile_image_url] => http://s3.amazonaws.com/twitter_product ... normal.png
[url] => http://twitter.com
[screen_name] => twitter
[name] => Twitter
[protected] =>
[followers_count] => 313718
[location] => San Francisco, CA
[id] => 783214
)
[created_at] => Thu Mar 05 00:48:31 +0000 2009
[favorited] =>
[in_reply_to_user_id] =>
[truncated] =>
[id] => 1281186929
[in_reply_to_screen_name] =>
[in_reply_to_status_id] =>
[source] => twitterfeed
)
The object is like an array of objects, I only included the first element here, but there is "[1] => stdClass Object" and so on after this one.