//my bad...on the previous example I mucked up the constructor, but it still runs anyway
//Di is correct
//two dollar signs with a variable that has a value makes the value a variable name.
//eg.
$var = "who"; //sets the variable to who
$$var = "me"; //now introduces the new variable 'who' and sets it to 'me'.
//I can now access the 'me' string by saying
echo "$who\n";
//or the accurate way, which basically says echo the variables' assigned variable.
echo "${$var}\n";
//Here's an object example of variable variables in an object.
class my_var {
//constructor
function my_var() { }
//assigns the given string as a variable name and returns it-- in order to preserve the variables outside of the function you have to use global declarations
function mkvar($name,$val) {
global $temp;
$temp = $name;
$$temp = $val;
return $$temp;
}
//a fake me out function that returns a null value
function delvar() {
return "";
}
}
global $temp;
$var = new my_var();
$$temp = $var->mkvar("say_hi","hello");
echo "$say_hi and ${$temp} are the same \n";
$$temp = $var->delvar();
echo "now the value of say_hi is ${$temp}";