> ... and, in fact, that /is/ how C behaves. The following code:
> int a = 2;
> a = a++;
> printf("a = [%d]\n", a);
> Will output "a = ". At least on Ubuntu 9 using gcc 4.3.3.
> So I retract my initial terse reply and apologize for misunderstanding
> your question.
It's not that difficult to understand ... we are talking about a scripting
language as PHP is
The code you wrote for C is not the equivalent while this is:
int a = 2, b;
b = a++;
printf("b = [%d]\n", b);
and b will be exactly 2.
In PHP you are not referencing that variable, you are overwriting variable $a
with an integer, 2, and that's it.
The incremented integer, 3, is simply lost in the silly logic of the operation.
The equivalent of your C code, in PHP, would be just this:
$a = 2;
print $a; // of course is 3, the initial $a is not lost
or, to be more explicit ...
$a = 2;
($a = &$a) and $a++;
Keep your friends updated—even when you’re not signed in.