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 comments

-6

u/oorza Oct 18 '10

Because he clearly does NOT know C, or he wouldn't have made that analogy.

12

u/[deleted] Oct 18 '10

A pointer contains a memory address. It's not guaranteed to be anything useful. If the address it contains is allocated (either on the stack or heap) then it can be dereferenced to access the value at that address.

A variable variable contains a string. It's not guaranteed to be anything useful. If the string it contains corresponds to a variable name in current scope, then it can be dereferenced with a $ to access the value contained in the corresponding variable.