tags:

views:

582

answers:

3

Hi guys, i hope that everyone here know the php 'variable variable' syntax:

$color = 'red';
$red = 'yes, im red';
echo $$color;
//output: 'yes, im red';

but my problem is: how this syntax is named? i'm trying to find the reference on php.net, with no results (i wanna know if this feature will be kept in php6, the others attributes, etc...)

+7  A: 

Variable Variables

And yes it will be kept in PHP6 as far as I know.

Ólafur Waage
Ooo, 10 seconds faster. you can have it. ;)
Paolo Bergantino
<3 You win sometimes though :)
Ólafur Waage
What keyword did u use to find that page?
DaNieL
Oh, ok, just sitch the select to 'online documentation'..lol
DaNieL
Variable variable in PHP
uuɐɯǝʃǝs
In the search box on PHP.net, select "all php.net sites" in the drop down.
Ólafur Waage
+5  A: 

Just to share some tips.

To avoid confusion, you may use the curly braces.

${$color}

One of my team member removed the double $, thinking of typo error. Perhaps doing so will avoid confusion.

uuɐɯǝʃǝs
The mantra: "if it aint broke don't fix it" unfortunately does not apply to programmers ;-).
Gamecat
+1 Nice tip. When reading code that I wrote months ago and see a double-dollar I sometimes get a little confused. Seconds later I realize what it´s meaning :)
Luiz Damim
A: 

Removing this from php would be a really pointless decision as this functionality comes really handy in many scenarios while having no real disadvantages / problems associated with it.

code_burgar