FacebookTwitterGoogle+Share

PHP stdClass property $t

Just recently one of my clients requested that I add a blogger feed on their website. Today I set about implementing that.

I found that I retrieve the data as JSON, which is super handy because of PHP’s json_decode function. You can retrieve the JSON through a URL like this: http://blog.alteredeffect.com/feeds/posts/default?alt=json

But I did run into an issue. Most things, when deJSONed, turned into stdClass objects. One property I needed to access was named “$t“, which as you may imagine I had some trouble accessing. I tried single quotes and escaping the $ character, but nothing seemed to work.

There’s almost definitely a better way, but I ended up casting to Array:

function getT( $obj ) {
	$t = (Array) $obj;
	return $t['$t'];
}

And it seemed to work fine.

 

Comments

  1. Brad says:

    Jeff says this works: $obj->{‘$t’}