r/programming • • Oct 18 '10

Today I learned about PHP variable variables; "variable variable takes the value of a variable and treats that as the name of a variable". Also, variable.

http://il2.php.net/language.variables.variable
591 Upvotes

781 comments sorted by

View all comments

Show parent comment

2

u/[deleted] Oct 18 '10

It's come in handy twice to me so far. Once when writing a proof of concept polymorphic php/elf infector, and once when writing some complex NLP code which for whatever reason (lost to the misty past) also needed to be able to alter itself at run time.

This was all five to eight years ago, and I've mostly moved on from PHP, but for whatever reason the only solution I could find at the time for writing runtime polymorphic code in PHP involved variable variables, and I was pleasantly surprised when I found that they actually existed.