Bug #73940 [NEW]: the associativity is uncertain for complex ++/-- operation

From: Date: Sun, 15 Jan 2017 05:31:41 +0000
Subject: Bug #73940 [NEW]: the associativity is uncertain for complex ++/-- operation
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-206626@lists.php.net to get a copy of this message
From: hu60 dot cn at gmail dot com Operating system: Windows & Linux PHP version: 7.1.0 Package: Scripting Engine problem Bug Type: Bug Bug description:the associativity is uncertain for complex ++/-- operation Description: ------------ $x = 8; $y = ++$x; $z = $x + --$x + $x; var_dump($x, $y, $z); // output: int(8) int(9) int(24) $x = 8; $y = ++$x; $z = ($a = $x) + --$x + $x; var_dump($x, $y, $z, $a); // output: int(8) int(9) int(25) int(9) It's so amazing! Should $x + --$x + $x be equal 24 or 25? Test script: --------------- <?php $x = 8; $y = ++$x; $z = $x + --$x + $x; var_dump($x, $y, $z); echo '<hr>'; $x = 8; $y = ++$x; $z = ($c = (($a = $x) + ($b = --$x))) + ($d = $x); var_dump($x, $y, $z, $a, $b, $c, $d); echo '<hr>'; $x = 8; $y = ++$x; $z = (($x) + (--$x)) + ($x); var_dump($x, $y, $z); echo '<hr>'; $x = 8; $y = ++$x; $z = ($a = $x) + --$x + $x; var_dump($x, $y, $z, $a); ?> Expected result: ---------------- int(8) int(9) int(25) int(8) int(9) int(25) int(9) int(8) int(17) int(8) int(8) int(9) int(25) int(8) int(9) int(25) int(9) Actual result: -------------- int(8) int(9) int(24) int(8) int(9) int(25) int(9) int(8) int(17) int(8) int(8) int(9) int(24) int(8) int(9) int(25) int(9) -- Edit bug report at https://bugs.php.net/bug.php?id=73940&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=73940&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=73940&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=73940&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=73940&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=73940&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=73940&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=73940&r=needscript Try newer version: https://bugs.php.net/fix.php?id=73940&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=73940&r=support Expected behavior: https://bugs.php.net/fix.php?id=73940&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=73940&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=73940&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=73940&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=73940&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=73940&r=dst IIS Stability: https://bugs.php.net/fix.php?id=73940&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=73940&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=73940&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=73940&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=73940&r=mysqlcfg

« previous php.bugs (#206626) next »