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

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


Since the name of your property is the string '$t', you can access it like this:

echo $object->{'$t'};

Alternatively, you can put the name of the property in a variable and use it like this:

$property_name = '$t';echo $object->$property_name;

You can see both of these in action on repl.it: https://repl.it/@jrunning/SpiritedTroubledWorkspace


Correct answer (also for PHP7) is:

$obj->{$field}


Have you tried:

$t = '$t'; // Single quotes are important.$object->$t;