|
Posted by Dana Cartwright on 10/06/05 15:04
"Chung Leong" <chernyshevsky@hotmail.com> wrote in message
news:1128564778.863249.81660@g43g2000cwa.googlegroups.com...
> Another example to consider is print ($i++ + $++). This'd be the
> sequence of events:
>
> 1. To perform the addition operation, A + B, PHP reads $i (which is 1)
> for A
> 2. PHP increment $i
> 3. PHP reads $i (which is now 2) for B
> 4. PHP increment $i again
> 5. PHP passes the result of A + B to print, which is 3
>
> So you see, post increment isn't the last thing that happens. It
> happens right after the variable is read.
Actually, in C the result of the expression $i++ + $i++ is undefined.
Indeed, it produces different results on different computers.
The PHP manual seems to not discuss this point (OK, I only glanced at it
briefly, in the section on expressions).
But the PHP manual *does* say "just as in C" several times, which makes me
think that one ought to be cautious of writing things in PHP which are
undefined in C. In other words, even though it works OK today, it might not
work OK tomorrow.
Navigation:
[Reply to this message]
|