Access property with define()'d token?

niglet

New Member
I'd like to do this:\[code\]<?phpdefine('X', 'attribute_name');// object $thing is created with member attribute_nameecho $thing->X;?>\[/code\]Attempting \[code\]$thing->X\[/code\], PHP takes X to be a property of $thing, and ignores the fact (rightly so) that it's a define()'d token. That in mind, I had expected \[code\]$thing->{X}\[/code\] to work, but no dice.The only solution I'v come up with is to use a man-in-the-middle variable, like so:\[code\]$n = X;echo $thing->$n;\[/code\]But this extra step seems fairly un PHP-esque. Any advice on a more graceful solution?
 
Back
Top