php at electricsurfer dot com
23-May-2003 12:25
Here's an example on operator precedence between -> and []
&
what happens with $object->$member[$array_element]
<?
class
c
{
var $a = array('a'=>'aa','b'=>'ab');
var $b =
'c';
function show()
{
echo $this->a['a']; // ->
1st
echo $this->a['b']; // outputs 'ab'
$a =
'a';
$b = 'b';
echo $this->$a[$a]; // [] 1st, not what I
expected
echo $this->$a[$b]; // does NOT output
'ab'
$this_a =& $this->$a; // work-around
echo
$this_a[$a]; // no question
echo $this_a[$b];
$a_arr =
array('a'=>'b');
echo $this->$a_arr[$a]; // [] 1st =>
outputs 'c'
}
}
$c = new c();
$c->show();
?>