Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!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:00:13 -0500 Organization: A noiseless patient Spider Lines: 108 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="U2FsdGVkX1+B+hh3H73cLYte37zMWJJC" User-Agent: slrn/0.9.9p1 (OpenBSD) Cancel-Lock: sha1:EpwLx+eYXT5Q2e0yq9XVfCgORHI= Xref: x330-a1.tempe.blueboxinc.net comp.lang.php:3695 On Sat, 22 Oct 2011 16:54:11 +0100, The Natural Philosopher wrote: > Luuk wrote: >> On 22-10-2011 17:08, Luuk wrote: >>> On 22-10-2011 16:37, The Natural Philosopher wrote: >>>> The Natural Philosopher wrote: >>>>> Luuk wrote: >>>>>> On 22-10-2011 01:32, The Natural Philosopher wrote: >>>>>>> try $foo=($foo++); >>>>>>> >>>>>>> But actually, why not just >>>>>>> >>>>>>> $foo+=1; >>>>>> >>>>>> Because they differ? >>>>>> >>>>>> $ php -r ' $foo=0; $foo=$foo++; print $foo."\n";' >>>>>> 0 >>>>>> $ php -r ' $foo=0; $foo=($foo++); print $foo."\n";' >>>>>> 0 >>>>> >>>>> That is surely a bug.. >>>>> >>>> >>>> viz >>>> >>>> ~$ cat test.c >>>> #include >>>> main() >>>> { >>>> int foo; >>>> foo=0; >>>> foo=(foo++); >>>> printf("%d\n",foo); >>>> } >>>> ~$ ./test >>>> 1 >>>> >>>> >>>> I thought PHP followed C operator precedence exactly.. >>>> >>>> >>> >>> it seems to follow PERL >>> >>> $ perl -e '$foo=0; $foo=$foo++; print $foo."\n";' >>> 0 >>> $ perl -e '$foo=0; $foo=($foo++); print $foo."\n";' >>> 0 >>> $ perl -e '$foo=0; $foo++; print $foo."\n";' >>> 1 >>> $ >>> >>> >> >> see: http://www.dartlang.org >> >> main() { >> int foo=0; >> foo=foo++; >> print('First test: ${foo}'); >> >> foo=0; >> foo=(foo++); >> print('Second test: ${foo}'); >> >> foo=0; >> foo++; >> print('Third test: ${foo}'); >> >> } >> >> which gives: >> First test: 0 >> Second test: 0 >> Third test: 1 >> >> > > still a bug in PHP where > > "Parentheses may be used to force precedence, if necessary. For > instance: (1 + 5) * 3 evaluates to 18" > > (from the manual) > > I THOUGHT the general rule was that the value of (entity) was always the > FINAL value after ALL internal operations had been carried out. > > Agreed its a crappy way to code, which is probably why no one has > noticed it. The thing is that PHP is doing the right thing there. Remember that $foo++ is not the same as ++$foo The former "returns" the value PRIOR to incrementing, the latter AFTER incrementing. Even wrapping $foo++ in parens won't change what it returns. Don't use one when you want the other. -- 93. If I decide to hold a double execution of the hero and an underling who failed or betrayed me, I will see to it that the hero is scheduled to go first. --Peter Anspach's list of things to do as an Evil Overlord