I know how PHP variable variables works, but have trouble understanding why this script outputs "I am r." instead of "I am B."
<?php
class fooo {
var $bar = 'I am bar.';
var $arr = array('I am A.', 'I am B.', 'I am C.');
var $r = 'I am r.';
}
$fooo = new fooo();
$arr = 'arr';
echo $fooo->$arr[1] . "\n";
//above line output
//I am r.
?>
$arrinside the class belongs to the class (a property of it). When you set the$arrinsidefooo()you do:$fooo->arr = 'arr';. The$arryou set now belongs to the normal scope and not the one inside the instanced object of the classfooo. Try to Google a bit on how scopes work in programming. It will become much more clearer :)$fooo->$arr[1]is equivalent to$fooo->{$arr[1]}