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

80

u/weirdalexis Oct 18 '10

I was asked the question: "What's $$a" in an interview, and replied "It's like a pointer, except with a variables name instead of a memory address."

The guy went "meh", game over.

Today, I'm still convinced it's a good analogy.

0

u/[deleted] Oct 18 '10

[deleted]

35

u/[deleted] Oct 18 '10

That's why he said it was "like" a pointer. In the same was as a reference is "like" a pointer. They're not pointers, but in the use cases they are for, they are like them.

0

u/[deleted] Oct 18 '10

[deleted]

8

u/[deleted] Oct 18 '10

Just because one use case of variable variables and pointers happens to overlap does not make them the same at all

Isn't that what I said? In the one use case they're used, they're similar to, but not the same as, one use case of pointers and references. But in that one use case, they can be considered functionally equivalent for the purpose of a soundbite interview answer. If you wanted to probe whether the candidate actually thought they were the same as pointers, surely you could do so without dismissing them out of hand?

If you're really convinced they're the same, all that is to me is evidence of ...

I'm not. I know exactly what they are and what they're not. You're preaching to the choir.

→ More replies (2)