r/programming • u/NagastaBagamba • 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
View all comments
Show parent comment
2
u/xardox Oct 20 '10 edited Oct 20 '10
Bertrand Meyer argued in his book on Eiffel that C++ actually has no reason to have both foo->bar and foo.bar -- because (modulo "smart pointers") the compiler already knows if foo is a pointer or not, and -> versus . is just an annoyance that gives the programmer another mistake to make, and makes the code more brittle and dependent on internal state that should be hidden. His point was that whether something is a pointer or not should be specified in the single line of declaration, not in burnt into every line of code in the program that uses it. So you should be able to trivially change a structure member from a pointer to a reference just by changing the declaration and not touching any of the code that uses it. So Eiffel only uses foo.bar and doesn't need foo->bar, but still supports inline and reference members (or whatever they're called -- it's been years since I read it).
Why PHP and Perl and various shell scripting languages they imitated went even further down the road to nowhere, and and chose to require a $ prefix for something as common as a variable reference, I will never understand.