How can I access an object attribute that starts with a number?

Viewed 8431

I'm working on an existing code base and got back an object with an attribute that starts with a number, which I can see if I call print_r on the object.

Let's say it's $Beeblebrox->2ndhead. When I try to access it like that, I get an error:

Parse error: syntax error, unexpected T_LNUMBER, expecting T_STRING or T_VARIABLE or '{' or '$'

How can I get that attribute?

3 Answers

You can do something like this too:

$aux = '2ndhead';
$Beeblebrox->$aux;
Related