Re: ++ BUG??
| From: | Ignacio Vazquez-Abrams | Date: | Sun, 26 Nov 2000 03:24:05 +0000 |
| Subject: | Re: ++ BUG?? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-27215@lists.php.net to get a copy of this message | ||
On Sat, 25 Nov 2000, Jason wrote:
> On Sun, Nov 26, 2000 at 03:22:09AM +0100, Marcin Orlowski wrote:
> >
> >
> > Hi,
> >
> > This:
> >
> > $idx=0;
> > [loop]
> > {
> > $idx = ($idx++)%2;
> > echo $idx;
> > }
> >
> > $idx = ($idx+1)%2;
>
> whether there's a bug there or not, it's ambiguous code. You're doing two
> assignments to $idx on the same line. $idx+1 and $idx++ are NOT equivalent.
> $idx = ($idx+1)%2 is better code and you don't have to worry about the bug.
>
Now, normally I don't argue in a public forum, but the PHP manual does say
"C-style pre- and post-increment and decrement operators". IIRC, C would
assign to the variable and then increment it. There should be no
ambiguity. Please correct me if I'm wrong.
--
Ignacio Vazquez-Abrams <ignacio@openservices.net>