ID: 43702 Updated by: [EMAIL PROTECTED] Reported By: gdiego at gmail dot com -Status: Open +Status: Bogus Bug Type: Arrays related Operating System: Irrelevant PHP Version: 5.2.5 New Comment:
Sorry, but your problem does not imply a bug in PHP itself. For a list of more appropriate places to ask for help using PHP, please visit http://www.php.net/support.php as this bug system is not the appropriate forum for asking support questions. Due to the volume of reports we can not explain in detail here why your report is not a bug. The support channels will be able to provide an explanation for you. Thank you for your interest in PHP. $a->{$z}['a'] Previous Comments: ------------------------------------------------------------------------ [2007-12-29 09:05:20] gdiego at gmail dot com Description: ------------ So, this is not really a bug itself but it's a problem. Let's say we have: class a { var $a = array('a'=>1); [...] some functions [...] }; Lets say a function inside the class does: var_dump($this->a); //this will dump $a array of class a. If we do var_dump($this->a['a']) it will dump integer 1. If we do: $z="a"; var_dump($this->$z); it will dump $a array of class a. Since here all is working fine because $z is used as a pointer. What happens with? $z="a"; var_dump($this->$z['a']); So, this will again dump the $a array in the class. The problem here is the following, because of the operator precedence, the index ['a'] is considered an index of $z which is a string. Then 'a' is casted to integer and interpreted as 0. $this->$z['a'] becomes the same as $this->$z[0] and, as $z[0] is 'a', this becomes $this->a (the array). This is not really a problem (even its not clear this precedence in the documentation as posted in other bug). My problem is that I couldn't find any way of telling the php interpreter that ['a'] should be considered as an index for the whole expression. ($this->$a)['a'] gives syntax error and I have been trying to find a way to do this without intermediate variables and couldn't figure out a solution. I know this example has no sense (who would really do this?) but still think there should be a way to specify the precedence (and if there is, it should be documentated in the operator precedence page, which lacks of the -> operator by the way). Thanks, Diego ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=43702&edit=1