3

so I acquired a json object from an API and json decoded it...

but then the returned object is of the following:

stdClass Object
(
    [id] => stdClass Object
        (
            [$t] => some string
        )
)

And as you can see there is a property with a $ sign in it

but when I do $object->id->$t <--that returns error since it thinks $t is a variable

how would I go about fetching that variable with $ sign?

hakre
  • 193,403
  • 52
  • 435
  • 836
pillarOfLight
  • 8,592
  • 15
  • 60
  • 90
  • Possible duplicate of [Get a PHP object property that is a number](http://stackoverflow.com/questions/9606340/get-a-php-object-property-that-is-a-number) - Which is only one of the similar ones. – hakre Aug 13 '12 at 18:49

1 Answers1

5

Encapsulate it as a single-quoted string:

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

Note that you cannot use double quotes for the same reason you cannot use $object->id->$t: PHP will attempt to interpolate $t. However, you could use double quotes if you escape the dollar sign:

echo $obj->id->{"\$t"};

You can see it working in this simple demo.

nickb
  • 59,313
  • 13
  • 108
  • 143