Re: ++ BUG??

From: Date: Sun, 26 Nov 2000 04:00:37 +0000
Subject: Re: ++ BUG??
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-27223@lists.php.net to get a copy of this message
On Sat, 25 Nov 2000, Jason wrote: > > > 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++ In C, foo(i++) marks i for incrementing at the end of the statement and then calls foo(i), and foo(i+1) evaluates i+1 and passes the result to foo(). > 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'. > My point is that this should not be undefined behavior because the PHP manual says "C-style ... operators". The behavior in C is very well-defined. Therefore there is either a problem in the Zend compiler or executor, or in the PHP manual. And to me this looks like a problem in the compiler or executor. -- Ignacio Vazquez-Abrams <ignacio@openservices.net>

« previous php.general (#27223) next »