RE: [PHP] Whacky increment/assignment logic with $foo++ vs ++$foo
| From: | Daevid Vincent | Date: | Wed, 07 Oct 2009 01:15:49 +0000 |
| Subject: | RE: [PHP] Whacky increment/assignment logic with $foo++ vs ++$foo | ||
| References: | 1 2 3 4 5 6 7 8 9 10 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-298703@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Paul M Foster [mailto:paulf@quillandmouse.com]
> Sent: Tuesday, October 06, 2009 6:28 AM
> To: php-general@lists.php.net
> Subject: Re: [PHP] Whacky increment/assignment logic with
> $foo++ vs ++$foo
>
> On Tue, Oct 06, 2009 at 08:51:17AM -0400, Bob McConnell wrote:
>
> > From: Joost [mailto:joost.t.hart@planet.nl]
> > > "Daevid Vincent" wrote:
> > >>> From: Ben Dunlap [mailto:bdunlap@agentintellect.com]
> >
> > > $a = $a++;
> >
> > I just think this is an ambiguous line of code that wasn't thought
> > through. The presence of the postfix operator makes the result
> > undefined, no matter what language you are using. It will
> be an accident
> > if you get the results you are expecting.
>
> The behavior of the ++ operator is the invention of Kernighan
> and Ritchie.
> I don't imagine they ever foresaw anyone doing something as silly as
>
> a = a++;
>
> except under the rarest of circumstances.
>
> Paul
Except that:
$a = 123;
$b = $a++;
echo $b; //gives 123, not 124
as you logically expect it to and common sense would dictate, regardless of
what K&R or anyone else says.