I'm using variable variables to try to assign a value to some (not all) private variables in a class using a public function and an array as input. However, the values don't seem to get assigned to the private vars. The code seems logical but am I missing something? Perhaps I'm going about it the wrong way. Any suggestions?
-Geates
"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom
"I do not offer answers, only considerations."
- Geates's Disclaimer
Code:
class aClass {
private $_fruitA;
private $_fruitB;
private $_fruitC;
public function set($inputArray)
{
foreach ($inputArray as $key=>$val)
{
$var = "this->_{$key}";
$$var = $val;
//prints nothing
print "this->_$key: ".$this->_fruit."\n";
//prints the $val assigned in $inputArray
print "\$\$var: ".$$var."\n\n";
}
}
}
$fruit = new aClass();
$fruit->set(array('fruitA' => 'apple', 'fruitB' => 'banana'));
-Geates
"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom
"I do not offer answers, only considerations."
- Geates's Disclaimer