Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: "Peter H. Coffin" Newsgroups: comp.lang.php Subject: Re: OT: and even in Dart .........Re: simple session question Date: Sat, 5 Nov 2011 15:04:26 -0500 Organization: A noiseless patient Spider Lines: 70 Message-ID: References: <8f4e82f6-e311-4064-9a83-56a4eb300d6c@t38g2000prg.googlegroups.com> <4ea1bf2b$0$293$14726298@news.sunsite.dk> <2t2bn8-n38.ln1@luuk.invalid.lan> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Injection-Info: mx04.eternal-september.org; posting-host="le/2G4+BNpieVhQI6uJ2Lw"; logging-data="14959"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18HA67sIzj+lic2ZEdFg/2W" User-Agent: slrn/0.9.9p1 (OpenBSD) Cancel-Lock: sha1:Zkm1dM+0PeK82ja+/z/UNhPP6vM= Xref: x330-a1.tempe.blueboxinc.net comp.lang.php:3696 On Sat, 22 Oct 2011 16:08:01 -0400, Norman Peelman wrote: > On 10/22/2011 01:34 PM, Thomas Mlynarczyk wrote: >> Luuk schrieb: >>> i did send a bug-report: >>> https://bugs.php.net/bug.php?id=60114 >> >> I do not see any bug here. I was confused because it's a crappy way to >> code, but it's clear why it works the way it does: >> >> $foo = 0; >> $foo = $foo++; >> >> is definitely identical to >> >> $foo = 0; >> $foo = ($foo++); >> >> since ++ has higher precedence than =. In fact, ($foo = $foo)++ does >> rightfully throw a parse error, since you can only increment a variable, >> not an expression. >> >> As mentioned before in this thread, the above code is equivalent to >> >> $foo = 0; >> $tmp = $foo; // $foo++ yields the previous value, which is 0 >> $foo = $foo + 1; // then $foo is incremented... >> $foo = $tmp; // ...and then re-assigned the old value >> >> It's the exact same procedure as it would be with $foo = $bar++. >> >> Greetings, >> Thomas >> > > No they are not the same. > > $foo = 0; > $foo = $foo++; > > It should be equivalent to: > > $foo = 0; // 0 > $foo = $foo; // 0 = 0 > $foo = $foo + 1; // 0 = (0 + 1) > > $foo++ means that the variable is to be incremented after the variable > is accessed. Something is clobbering that increment. Yes. The ASSIGNMENT back to $foo is clobbering it. The increment happens immediately after access, before the VALUE is passed back to the assignment. > ++$foo means that the variable is to be incremented piror to the > variable being accessed. Works as expected. > > > Haven't seen the source code but there must be some temporary > variable that's getting clobbered for the $foo++ example. It's just happening in the proper order. increment happens before assignment, exactly per http://php.net/manual/en/language.operators.precedence.php The catch is that the assignment is destroying the increment, because the variable access happened BEFORE the increment. -- 17. When I employ people as advisors, I will occasionally listen to their advice. --Peter Anspach's list of things to do as an Evil Overlord