1

I am working with a database created by a university professor's intern. Many of the fields have names like 'Revenues_(budget)'.

Currently when working with objects that have the fields as properties I do something like

$f = 'Revenues_(budget)';
echo $obj->$f;

This works fine but I was wondering if there might be a more elegant or at least concise way to handle these?

jerrygarciuh
  • 21,158
  • 26
  • 82
  • 139
  • Possible duplicate of [Special characters in property name of object](https://stackoverflow.com/questions/10455775/special-characters-in-property-name-of-object) – Don't Panic Jun 02 '17 at 17:08

1 Answers1

4

You can do that in one expression:

echo $obj->{'Revenues_(budget)'};
zerkms
  • 249,484
  • 69
  • 436
  • 539