#42152 [Com]: Operator Precedence: postincrement before '['
| From: | smlerman at gmail dot com | Date: | Tue, 31 Jul 2007 13:23:32 +0000 |
| Subject: | #42152 [Com]: Operator Precedence: postincrement before '[' | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-115602@lists.php.net to get a copy of this message | ||
ID: 42152
Comment by: smlerman at gmail dot com
Reported By: php at tfwasmus dot enschedenet dot nl
Status: Feedback
Bug Type: Scripting Engine problem
Operating System: Windows Xp x64
PHP Version: 5CVS-2007-07-30 (snap)
New Comment:
Last I knew, using a variable that you post-increment (and maybe
pre-increment, can't remember for sure) elsewhere in the same statement
results in undefined behavior.
Previous Comments:
------------------------------------------------------------------------
[2007-07-31 11:33:46] jani@php.net
Either I missed something but = has lower precedence than [ ?
------------------------------------------------------------------------
[2007-07-30 23:26:44] php at tfwasmus dot enschedenet dot nl
Description:
------------
According to the operator precedence
(http://www.php.net/manual/en/language.operators.php#language.operators.precedence),
a (post)increment should be evalued after the '['.
It seems that isn't true in assigning to an array in PHP5 anymore,
while it was in PHP4. Latest snapshots of both checked (30-07-2007).
This could also be a documentation problem.
Reproduce code:
---------------
<?php
$k = 1;
$a = array();
$a[$k] = $k++;
var_dump($a,$k);
?>
Expected result:
----------------
array(1) {
[1]=>
int(1)
}
int(2)
Actual result:
--------------
array(1) {
[2]=>
int(1)
}
int(2)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=42152&edit=1