|
Posted by Steve on 04/10/07 15:15
"Vince Morgan" <vinhar@REMOVEoptusnet.com.au> wrote in message
news:461b8776$0$16556$afc38c87@news.optusnet.com.au...
|
| "Steve" <no.one@example.com> wrote in message
| news:WIDSh.101$Xq6.16@newsfe12.lga...
|
| > no...i think the operation as a whole is considered before the = ... so,
| ++
| > would increment then the assignment would be made (lhs = rhs). afaicr.
you
| > can further test this by ++$imagenum...the pre/post incrementor should
| have
| > NO impact on the final lhs result if this precedence processing is true.
|
| Steve, run the following and then look again at the original OP's
| expression.
| You've got the experience to work this out I think.
oh how mistaken you probably are! ;^)
however...it doesn't have to do with precedence so much as state. notice:
$m = 0
for ($i = 0; $i < 10; $i++)
{
$m = $m++;
echo '<pre>' . $m . '</pre>';
}
that will return ten zeros. changing this line:
$m = ++$m;
will return 1 though 10.
logically interpreting the former however, we should be able to express $m =
$m++ like this:
$m = $m;
$m++;
which is why it's so retarded to write it like that in the first place! but,
i digress...
essentially our 'bug' is this, that $m = $m++ nullifies the incrementation.
the lhs of $m makes the rhs of $m++ impossible...$m can only be incremented
if $m is known...thus, it remains 0 all the time. the two seem to be
dependent on each other.
clear as mud? why then does the pre-incrementor work? because ++$m considers
$m BEFORE the rhs operation sets the lhs variable. so, all is known...at all
times. however in $m = $m++, the lhs $m is pending a value assignment and
$m++ only increments after the line $m = $m++ is executed...it's a catch 22.
are you thinking, 'BAD PHP! BAD! BAD!'? well...try this:
<script type="text/javascript">
var m = 0;
var htm = '';
for (var i = 0; i < 10; i++)
{
m = m++;
htm += '<pre>' + m + '</pre>';
}
document.write(htm);
</script>
;^)
[Back to original message]
|