How can I access an object property named as a variable in php?

Viewed 83500

A Google APIs encoded in JSON returned an object such as this

[updated] => stdClass Object
(
 [$t] => 2010-08-18T19:17:42.026Z
)

Anyone knows how can I access the $t value?

$object->$t obviously returns

Notice: Undefined variable: t in /usr/local/...

Fatal error: Cannot access empty property in /....

5 Answers

Correct answer (also for PHP7) is:

$obj->{$field}

this works on php 5 and 7

$props=get_object_vars($object);
echo $props[$t];
Related