I have an engine that does some mathematical and logical operations by taking formulas, operands and operators from a file.
All the operations are executed in an
$x = 1;
$result = $x++-++$x; // works
$result = $x+++++$x; // fails
$result = $x++ + ++$x; // works again
The PHP parser is searching for the
++ sign before the last
+ sign, and the syntax
($x++)++ makes no sense, due to the fact that the increment operator should be applied to a variable (and not an integer, which is the result of the first
The precedence of the operator's operations can be found here:
$x+++++$x; ^ php parser starts here, find $x++ ^ here there is a new ++, which has hight precedence to the next + char ^ here is the last +, which the php parser will find last.
When the two
++ split with a minus sign, the code is actually
$x++ - ++$x, one which the PHP parser can understand.
This is also the reason why
$x++ + ++$x works.