note 32286 added to language.types.object
| From: | php at electricsurfer dot com | Date: | Thu, 22 May 2003 14:25:40 +0000 |
| Subject: | note 32286 added to language.types.object | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-48825@lists.php.net to get a copy of this message | ||
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();
?>
----
Manual Page -- http://www.php.net/manual/en/language.types.object.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32286
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32286&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32286&report=yes