Re: ++ BUG??
| From: | Jason | Date: | Sun, 26 Nov 2000 03:50:17 +0000 |
| Subject: | Re: ++ BUG?? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-27221@lists.php.net to get a copy of this message | ||
> > 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.
yes, foo($i++) should do foo($i) and then do $i = $i + 1.
However, foo($i+1) should do foo($i+1) and increment $i. So $i+1 and $i++
are not equivalent. see what I mean?
so trying to do $i = ($i++)%2 is doing two assignments to $i.
One is the $i = ... part and the other is the $i++ part. That's where it
gets ambiguous.
I'd say this isn't a bug, but more along the lines of 'undefined behavior'.