Bug #66089 [Opn->Nab]: The result of post-increment/post-decrement operation is included in result

From: Date: Wed, 13 Nov 2013 14:29:26 +0000
Subject: Bug #66089 [Opn->Nab]: 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-182737@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 Updated by: derick@php.net Reported by: alexanderhook at gmail dot com Summary: The result of post-increment/post-decrement operation is included in result -Status: Open +Status: Not a bug Type: Bug Package: Variables related Operating System: Windows 7, Ubuntu 12 PHP Version: 5.4.21 Block user comment: N Private report: N 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 Reading and writing the same variable during an assignment gives undefined behaviour. Previous Comments: ------------------------------------------------------------------------ [2013-11-13 14:23:08] alexanderhook at gmail dot com Test: $i = 1; $sum = $i + ($i++); assert($sum == 2); $i = 1; $sum = $i + $i--; assert($sum == 2); ------------------------------------------------------------------------ [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

« previous php.bugs (#182737) next »