#31513 [Opn]: wrong expression execution order

From: Date: Wed, 12 Jan 2005 12:18:46 +0000
Subject: #31513 [Opn]: wrong expression execution order
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-71948@lists.php.net to get a copy of this message
ID: 31513 User updated by: dan at yes dot lt Reported By: dan at yes dot lt Status: Open Bug Type: *General Issues Operating System: any PHP Version: 5.0.3 New Comment: it works if there is no $b =&$a reference, and fails, if there is that reference... Previous Comments: ------------------------------------------------------------------------ [2005-01-12 13:17:38] dan at yes dot lt <?php $a = 10; $b = &$a; $a = 10; $c = $a++ + ++$a; // Gauname 22, kaip ir turi buti echo "$c\n\n"; $a = 10; $c = ++$a + $a++; // Gauname 23, nors turetu buti 22 echo "$c\n\n"; ?> ------------------------------------------------------------------------ [2005-01-12 12:53:28] derick@php.net You can never rely on this behavior, not in any language that I know about. Do not use the post/pre inc operation in assignments like this. ------------------------------------------------------------------------ [2005-01-12 11:58:30] dan at yes dot lt Description: ------------ Arithmetic expression execution returns unexpected results with ++ or -- operators. Reproduce code: --------------- $a = 10; $c = $a++ + ++$a; echo "$c\n"; $a = 10; $c = ++$a + $a++; echo "$c\n"; Expected result: ---------------- 22 22 Actual result: -------------- 22 23 <- ?? Why ?? ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=31513&edit=1

« previous php.bugs (#71948) next »