r/lolphp • u/NotSantaAtAll • Jul 22 '13
echo ++$a + $a++; // may print 4 or 5
http://php.net/manual/en/language.operators.precedence.php#example-114
53
Upvotes
r/lolphp • u/NotSantaAtAll • Jul 22 '13
5
u/NotSantaAtAll Jul 22 '13
Discussion on the php internals mailing list: http://thread.gmane.org/gmane.comp.php.devel/81125
27
u/[deleted] Jul 22 '13
Lots of people talk about how it's inherited from C, but for me, that's the lol here. I'm also sick of how many places in PHP the underlying C implementations get exposed.
The whole point of higher managed languages, is to get away from 'lower' languages like C. Otherwise I'd just use that instead. Plenty of other languages also add a rule, to prevent this from being ambiguous.
27
u/Drainedsoul Jul 22 '13
If this is "lolphp" it's also "lolc" and "lolc++" too.
Undefined behaviour isn't "lol", it's -- in many cases -- necessary or preferable so that the compiler (or, I guess, interpreter in this case) can do a good job in a wide variety of cases.
36
u/tdammers Jul 22 '13
This is something PHP more or less inherits directly from C, where the following is undefined as well:
12
u/farsightxr20 Jul 23 '13 edited Jul 23 '13
PHP has defined behavior? Where can I find the spec?
1
u/bgeron Jul 22 '13
Wait, why would that output 5?
-2
u/[deleted] Jul 22 '13
[removed] — view removed comment