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
2009-08-25 15:04:41
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
2009-08-25 15:09:44
@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
2009-08-25 15:13:14
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
2009-08-25 16:01:03
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
2009-08-25 16:57:12
+7
A:
It means "The author should be using an associative array".
(It is a variable variable)
David Dorward
2009-08-25 15:05:12