RE: [PHP] ++ BUG??

From: Date: Mon, 27 Nov 2000 11:54:47 +0000
Subject: RE: [PHP] ++ BUG??
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-27339@lists.php.net to get a copy of this message
A prefix increment would work I guess.. $idx = (++$idx)%2; but $idx = !$idx; looks like it does the same. (alternate between 0 and 1) > -----Original Message----- > From: Marco Roccioletti [mailto:marco.roccioletti@inalp.com] > Sent: 27 November 2000 11:18 > To: Marcin Orlowski; php-general@lists.php.net > Subject: Re: [PHP] ++ BUG?? > > > 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)? > > Hi! > > > $i= ($i++)%2; > > is processed as follows: > > 1) evaluate right-hand expression > 2) increment $i > 3) assign result of expression to $i > > so, let's say $i == 0 > > 1) expression evalutated to 0 > 2) $i incremented to 1 > 3) result (0) assigned to $i => $i=0 > > No bug there! > > Cheers, > Marco > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > >

« previous php.general (#27339) next »