From: gdiego at gmail dot com Operating system: Irrelevant PHP version: 5.2.5 PHP Bug Type: Arrays related Bug description: Operator precedence problem
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 bug report at http://bugs.php.net/?id=43702&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=43702&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=43702&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=43702&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=43702&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=43702&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=43702&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=43702&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=43702&r=needscript Try newer version: http://bugs.php.net/fix.php?id=43702&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=43702&r=support Expected behavior: http://bugs.php.net/fix.php?id=43702&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=43702&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=43702&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=43702&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=43702&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=43702&r=dst IIS Stability: http://bugs.php.net/fix.php?id=43702&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=43702&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=43702&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=43702&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=43702&r=mysqlcfg