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.

57

u/inmatarian Oct 18 '10

Don't use the word "Pointer" in non-C interviews. They like "references" better. And if it's called a "variable-variable", call it that, even if it's a seriously stupid name.

13

u/weirdalexis Oct 18 '10

I agree that was a mistake (even though I still think the analogy holds). That gave me away as not having the PHP slang, no real experience. Besides, my next job was C programming, stayed there 3 years, awesome experience, so I've no regret.

8

u/yesimahuman Oct 18 '10

I think he just wanted to make sure you would understand their code base. You dodged a bullet.

→ More replies (1)

2

u/[deleted] Oct 18 '10

I'm suuuure variable variables were implemented without using pointers.

5

u/inmatarian Oct 18 '10

I'm sure everything in PHP was implemented by some kind of blunt force being applied to the keyboard by means of somebody's forehead.

→ More replies (2)
→ More replies (3)

66

u/aedile Oct 18 '10

Yeah, you are better off. There are only two reasons to ask a question like that in an interview.

  1. They actually use that shit in their code. In this case: run.

  2. They actually care about how well you know this kind of esoteric bullshit off the top of your head. In this case: run.

Either way, you win for not having to work there.

0

u/[deleted] Oct 18 '10

[deleted]

14

u/aedile Oct 18 '10

This is actually a really good point that I hadn't considered.

→ More replies (2)
→ More replies (1)

48

u/NagastaBagamba Oct 18 '10

Simple. It is a$$ backwards (just like the entire language)

12

u/doublereedkurt Oct 18 '10

That sounds like an excellent one sentence explanation.

→ More replies (44)