Re: ++ BUG??

From: Date: Sun, 26 Nov 2000 02:28:56 +0000
Subject: Re: ++ BUG??
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-27211@lists.php.net to get a copy of this message
On Sun, 26 Nov 2000, Marcin Orlowski wrote: > > > Hi, > > 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)? > > > Regards, > -- > Press any key to continue or any other key to quit... > > Marcin > http://wfmh.org.pl/~carlos/ > > mailto:carlos@wfmh.org.pl > 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. For your problem, try using ++$idx and report on your findings. -- Ignacio Vazquez-Abrams <ignacio@openservices.net>

« previous php.general (#27211) next »