in reply to Re: Re: precedence question
in thread precedence question

Take this example:
$a = 30; $one = ($a += 5) + ($a -= 10); print "a=$a one= $one \n";
Output: a=25 one=50 it looks the the += is being updated after the calculation: so (30) + (30 - 10) = 50 then after the line passes you see $a is 25. Not sure if this is how it should work or not seems kinda fishy that the += is not proccessed the same way -= is. but i still don't understand what you are trying to add up here? $result = ($a+=5) + ($a-=10); is not very intuitive. Do you expect $result to be the result status of the += or -=? I am not sure what I would even expect $result to hold += and -= are not really normal arithmatic operators...

-Waswas

Replies are listed 'Best First'.
Re: Re: Re: Re: precedence question
by Aron (Initiate) on Aug 09, 2002 at 22:48 UTC
    The way it was explained to me, the value of $a is modified with all the parenthetical calls, and then the result is added. So the actual calculation would end up being:
    $a = 30
    then $a = 35 (after the +=5)
    then $a = 25 (after the -=10)
    then $one = $a + $a, or (25)+(25) = 50, our answer.
    I knew the code wasn't intuitive; it was presented as a specifically nonintuitive snippet in order to show the problems inherent in unclear code, in the example I was looking at. I got curious as to the result, and fretted over it until Zaxo laid it out for me.