#40755 [Opn->Bgs]: Increment/Decrement operator calculation oddity
| From: | derick@php.net | Date: | Thu, 08 Mar 2007 08:39:33 +0000 |
| Subject: | #40755 [Opn->Bgs]: Increment/Decrement operator calculation oddity | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-110087@lists.php.net to get a copy of this message | ||
ID: 40755
Updated by: derick@php.net
Reported By: henson dot garth at gmail dot com
-Status: Open
+Status: Bogus
Bug Type: Math related
Operating System: Linux
PHP Version: 5.2.1
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
Using and modifying the same variable when using post/pre-
decrement/increment is undefined (and not only in PHP).
Previous Comments:
------------------------------------------------------------------------
[2007-03-08 01:43:13] henson dot garth at gmail dot com
Description:
------------
The increment/decrement operators seem to calculate out of order
compared to other languages and even previous versions of PHP. I
compared this report numerous times against a 4.3.11 install that I am
running to verify the inconsistency. In the case of PHP 5.2.x, the
increment operator seems to be processed in an inappropriate order to
the rest of the statement. In 4.3.11, everything is presented just as
expected (as my Expected results display below).
Reproduce code:
---------------
$a = array(); // Begin Test 1
$b = 0;
$a[$b++] = $b;
var_dump($a);
$a = array(); // Begin Test 2
$b = 0;
$a[$b] = $b++;
var_dump($a);
$a = array(); // Begin Test 3
$b = 10;
$a[$b--] = $b;
var_dump($a);
$a = array(); // Begin Test 4
$b = 10;
$a[$b] = $b--;
var_dump($a);
Expected result:
----------------
array(1){[0] => int(1)}
array(1){[0] => int(0)}
array(1){[10] => int(9)}
array(1){[10] => int(10)}
Actual result:
--------------
array(1){[0] => int(1)}
array(1){[1] => int(0)}
array(1){[10] => int(9)}
array(1){[9] => int(10)}
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=40755&edit=1