|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40755 Increment/Decrement operator calculation oddity
Submitted: 2007-03-08 01:43 UTC Modified: 2007-03-08 08:39 UTC
From: henson dot garth at gmail dot com Assigned:
Status: Not a bug Package: Math related
PHP Version: 5.2.1 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
48 + 16 = ?
Subscribe to this entry?

 [2007-03-08 01:43 UTC] henson dot garth at gmail dot com
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;

$a = array(); // Begin Test 2
$b = 0;
$a[$b] = $b++;

$a = array(); // Begin Test 3
$b = 10;
$a[$b--] = $b;

$a = array(); // Begin Test 4
$b = 10;
$a[$b] = $b--;

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)}


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-03-08 08:39 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

Using and modifying the same variable when using post/pre- decrement/increment is undefined (and not only in PHP).
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Mon Jun 05 21:03:37 2023 UTC