/    Sign up×
Community /Pin to ProfileBookmark

Accessing stdClass Object (why doesn’t this work…)

I’m totally lost on this one. I’m receiving the following from a twitter API:

[code=php]stdClass Object
(
[0] => SimpleXMLElement Object
(
[created_at] => Wed Nov 05 13:19:41 +0000 2008
[id] => 991616764
[text] => This is my current twitter status
[source] => Twinkle
[truncated] => false
[in_reply_to_status_id] => SimpleXMLElement Object
(
)

[in_reply_to_user_id] => SimpleXMLElement Object
(
)

[favorited] => false
[user] => SimpleXMLElement Object
(
[id] => 12008842
[name] => Justin Schroeder
[screen_name] => jpschroeder
[location] => iPhone: 39.279629,-94.580763
[description] => Pilot/Web Designer
[profile_image_url] => http://s3.amazonaws.com/twitter_production/profile_images/56667821/twitter_me_normal.jpg
[url] => http://www.jpschroeder.com
[protected] => false
[followers_count] => 12
)

)

)[/code]

I have tried everything to access these variables. I’m sure I’m just missing something really easy. I’ve tried these things:

[code=php]

$message->0->text

$message->’0′->text

$num = 0;
$message->$num->text

object_to_array($message) //this returns nothing at all!!

print($message->xpath(“//text”));

[/code]

please help if you can! thanks.

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@jpschroederauthorNov 12.2008 — bump* i really need help on this one guys!
Copy linkTweet thisAlerts:
@jim_kellerNov 13.2008 — What version of PHP are you running? I tried the following to create an object similar to what you're seeing, and was able to print the property "0" as long as I stored the property name in a variable, like so:

[code=php]<?php

$zero = 0;

//
// Create a similar object with a property of index '0'
//
$tc = new stdClass();

$arr = new stdClass();
$arr->one = 1;
$arr->two = 2;


$tc->$zero = $arr;


//
// Print out the object
//
print_r( $tc );

//
// Print the Array
//

print_r( $tc->$zero );
?>
[/code]
×

Success!

Help @jpschroeder spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...