Re: Whacky increment/assignment logic with $foo++ vs ++$foo
| From: | Ben Dunlap | Date: | Fri, 02 Oct 2009 21:37:48 +0000 |
| Subject: | Re: Whacky increment/assignment logic with $foo++ vs ++$foo | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-298491@lists.php.net to get a copy of this message | ||
> My issue is that I see no reason to do the ASSIGNMENT FIRST and THEN
> INCREMENT.
>
> That's just counter intuitive. In the case of $foo = $num++, everything to
> the right of the = should be computed FIRST and THEN handed off to the left
> side. This particular expression (and I'm unaware of any other PHP
> expression that works this way) chooses to do some "FM" (f'n magic) and do
> an assignment FIRST and THEN increment.
It's not the expression that works that way -- it's the operator. The
post-increment operator /always/ does its work after the expression
that it's in has been evaluated.
Are you thinking it would be more intuitive if that operator departed
from its normal behavior in this one special case?
Ben