Bug #66089 [Opn]: The result of post-increment/post-decrement operation is included in result
| From: | alexanderhook at gmail dot com | Date: | Wed, 13 Nov 2013 14:23:08 +0000 |
| Subject: | Bug #66089 [Opn]: The result of post-increment/post-decrement operation is included in result | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-182736@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=66089&edit=1
ID: 66089
User updated by: alexanderhook at gmail dot com
Reported by: alexanderhook at gmail dot com
Summary: The result of post-increment/post-decrement
operation is included in result
Status: Open
Type: Bug
Package: Variables related
-Operating System: Windows, Ubuntu
+Operating System: Windows 7, Ubuntu 12
PHP Version: 5.4.21
Block user comment: N
Private report: N
New Comment:
Test:
$i = 1;
$sum = $i + ($i++);
assert($sum == 2);
$i = 1;
$sum = $i + $i--;
assert($sum == 2);
Previous Comments:
------------------------------------------------------------------------
[2013-11-13 14:16:37] alexanderhook at gmail dot com
Description:
------------
In some cases, if variable is has participation in expression with post-increment, then the result
of post-increment operation is included in the result of the whole expression.
Test script:
---------------
$i = 1;
$sum = $i + ($i++); //3 , but should be 2
$i = 1;
$sum = 0 + $i + ($i++); //2 , correct
$i = 1;
$sum = $i + $i + ($i++); //3 , correct
$i = 1;
$sum = $i + $i--; // 1
$i = 1;
$sum = 0 + $i + $i--; // 2
$i = 1;
$sum = $i + $i + $i--; // 3
Expected result:
----------------
$i = 1;
$sum = $i + ($i++); //2
$i = 1;
$sum = 0 + $i + ($i++); //2
$i = 1;
$sum = $i + $i + ($i++); //3
$i = 1;
$sum = $i + $i--; // 2
$i = 1;
$sum = 0 + $i + $i--; // 2
$i = 1;
$sum = $i + $i + $i--; // 3
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=66089&edit=1