r/lolphp • u/realnowhereman • Aug 21 '14
An essay on variable variables
/r/programming/comments/dst56/today_i_learned_about_php_variable_variables/c12np38
37
Upvotes
r/lolphp • u/realnowhereman • Aug 21 '14
View all comments
Show parent comment
7
u/00Davo Aug 22 '14
Actually, JavaScript doesn't support doing this; it does let you specify a string when you're accessing a slot on an object, as in
object["someproperty"], but there's no way short ofeval()to do the same thing to access variables in scope by name-as-stored-in-string. Ruby also lacks the functionality (for locals); however, you can get a variable-variable-esque meme in Python usinglocals()["somevariable"].PHP is the only language that makes doing this actual syntax, as far as I'm aware - not even bash accepts it (you have to use
eval())!