Re: Whacky increment/assignment logic with $foo++ vs ++$foo

From: Date: Fri, 02 Oct 2009 22:30:11 +0000
Subject: Re: Whacky increment/assignment logic with $foo++ vs ++$foo
References: 1 2 3 4 5 6 7  Groups: php.general 
Request: Send a blank email to php-general+get-298501@lists.php.net to get a copy of this message
On Oct 2, 2009, at 15:22, Daevid Vincent wrote:
-----Original Message----- From: Ben Dunlap [mailto:bdunlap@agentintellect.com] Sent: Friday, October 02, 2009 2:58 PM To: php-general@lists.php.net; Daevid Vincent Subject: Re: [PHP] Whacky increment/assignment logic with $foo++ vs ++$foo
mind-blowing. What the heck /is/ supposed to happen when
you do this:
$a = 2; $a = $a++; echo $a; Seems like any way you slice it the output should be 3. I
guess what's ... and, in fact, that /is/ how C behaves. The following code: int a = 2; a = a++; printf("a = [%d]\n", a); Will output "a = [3]". At least on Ubuntu 9 using gcc 4.3.3. So I retract my initial terse reply and apologize for misunderstanding your question. Ben
EXACTLY! :) God (or diety of your choice) bless you for "getting" what I'm saying and proving that it's not "C" like either. That just adds credence to my/our argument. d
I think if you rewrote the above example as int a = 2; b = a++; printf("b = [%d]\n", b); "b" would be 2 when printed. However, after the second line (b = a++;) finished executing, "a" would then be 3.

« previous php.general (#298501) next »