#42152 [Fbk->Csd]: Operator Precedence: postincrement before '['
| From: | php at tfwasmus dot enschedenet dot nl | Date: | Tue, 31 Jul 2007 15:13:16 +0000 |
| Subject: | #42152 [Fbk->Csd]: Operator Precedence: postincrement before '[' | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-115607@lists.php.net to get a copy of this message | ||
ID: 42152
User updated by: php at tfwasmus dot enschedenet dot nl
Reported By: php at tfwasmus dot enschedenet dot nl
-Status: Feedback
+Status: Closed
Bug Type: Scripting Engine problem
Operating System: Windows Xp x64
PHP Version: 5CVS-2007-07-30 (snap)
New Comment:
Hmm, after some consultation & a good night sleep I agree it's not a
bug in operator precedence. It's more an undefined state of the operand
which is the problem.
Indeed: undefined behaviour, so the difference between PHP4 & PHP5
should not matter: a statement like this just shouldn't be used/relied
upon.
The fact it's behaviour has changed between versions is however IMO
enough reason to keep this in the bug database for people to find.
Previous Comments:
------------------------------------------------------------------------
[2007-07-31 13:23:32] smlerman at gmail dot com
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.
------------------------------------------------------------------------
[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