Re: ++ BUG?? (fwd)

From: Date: Sun, 26 Nov 2000 03:11:38 +0000
Subject: Re: ++ BUG?? (fwd)
Groups: php.dev 
Request: Send a blank email to php-dev+get-39133@lists.php.net to get a copy of this message
Sorry to duplicate this message onto php-dev, but I have managed to duplicate this behavior myself. It seems that the actual post(inc|dec)rement operations are happening at the wrong time. They seem to be happening before the assignment instead of after the whole statement. Pre operations work as expected. -- Ignacio Vazquez-Abrams <ignacio@openservices.net> ---------- Forwarded message ---------- Date: Sat, 25 Nov 2000 21:28:56 -0500 (EST) From: Ignacio Vazquez-Abrams <ignacio@openservices.net> To: Marcin Orlowski <carlos@amiga.com.pl> Cc: php-general@lists.php.net Subject: Re: [PHP] ++ BUG?? On Sun, 26 Nov 2000, Marcin Orlowski wrote: > This: > > $idx=0; > [loop] > { > $idx = ($idx++)%2; > echo $idx; > } > > does not work as expected (idx is always 0). But this: > > $idx = ($idx+1)%2; > > will do act correctly. Known bug (PHP4.0.3/debian)? That possibly is a bug, but not in the way you're thinking. Let's work through the code: 1) $idx is retrieved into X 2) X is mod'd 2 3) X is stored into $idx 4) $idx is incremented That's how it works in C. What's probably happening is that the Zend executor is swapping steps 3 and 4. THIS is the real bug. -- Ignacio Vazquez-Abrams <ignacio@openservices.net>

« previous php.dev (#39133) next »