|
Posted by Hilarion on 10/17/08 11:29
>>> But much harder to accept is and I fail to see the logic in it,
>>> is the following :
>>> $i = 1;
>>> print($i++);
>>> This will print 1 and only afterward will the value of $i be increased
>>> by 1. It is between (), so logic tells me first $i++ and then print.
>>> [snip]
>>
>> print is a language construct, not actually a function. That means that
>> the parentheses are optional.
>> [snip]
>
> My two cents:
> Post-increment operator does incrementation after the whole instruction
> (which contains it) is executed, not after the expression containing it
> is executed, so it does not matter if you are using some language construct
> like "print" or "echo" or some function or expressions with different
> operator priority and parentheses.
>
> Example:
>
> some_function(($i++ * 2) + 4) | 7);
>
> is equivalent to:
>
> some_function(($i * 2) + 4) | 7); $i += 1;
>
>
> Example for pre-increment operator:
>
> some_function((++$i * 2) + 4) | 7);
>
> is equivalent to:
>
> $i += 1; some_function(($i * 2) + 4) | 7);
I was wrong when I was writing it. If you are reading this post (possibly
in some newsgroup archives), then read the post by Chung Leong in this thread.
He described the operator correctly.
Hilarion
Navigation:
[Reply to this message]
|