On 17 March 2004 17:09, Chris W. Parker wrote:

> 
> $var++ is a post incrementer meaning the value is updated at the next
> command*.

> * i'm not exactly sure how the compiler determines when to post
> increment, but i think i'm correct.

Not quite -- the increment is performed immediately after the access -- in
fact, as part of the same operation.  So:

    $x = 3;
    $y = ($x++ * 2) + $x;

is likely to give you $y==10, not 9.

(I say "is likely to", because you don't have any absolute cast-iron
guarantees that a compiler won't, if it thinks it has good reason, commute
the above to $x + ($x++ * 2), which would give you $y==9!  In general, it's
best to regard the value of a pre- or post-incremented variable as uncertain
in the rest of the expression containing it.)

Cheers!

Mike

---------------------------------------------------------------------
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730      Fax:  +44 113 283 3211 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to