tags:

views:

132

answers:

2

What does the double $ statement stands for in PHP?

+12  A: 

It means a variable variable:

$a = 'b';
$b = 'test';
print $$a; // test

For the most part (although there are exceptions if you know what you're doing) they are bad practice and whenever you see someone using them arrays are probably the better idea.

Paolo Bergantino
You're correct, but how about an example for the newbies of why you'd use it? IIRC, it was largely for superglobals, etc, so most won't know when or why to use it, let alone what it is for.
The Wicked Flea
@the wicked flea: If you need or want variable variables, something is wrong with your code. Scrap it and rethink the problem. Variable variables is usually fixed with arrays and dividing your code into classes/functions.
OIS
I was going to post an example where variable variables might come in handy. Couldn't find one that could not be implemented more elegantly without, though :)
jensgram
I know that CakePHP internally uses some variable variables to handle its model creation. It's a lot of edge cases to be sure, but I wouldn't say they are NEVER needed, certainly not unless you know what you are doing.
Paolo Bergantino
+7  A: 

It means "The author should be using an associative array".

(It is a variable variable)

David Dorward