Posted by Hilarion on 11/16/64 11:28
>> 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);
Hilarion
[Back to original message]
|