Re: Whacky increment/assignment logic with $foo++ vs ++$foo

From: Date: Sat, 03 Oct 2009 14:52:36 +0000
Subject: Re: Whacky increment/assignment logic with $foo++ vs ++$foo
References: 1 2 3 4 5  Groups: php.general 
Request: Send a blank email to php-general+get-298526@lists.php.net to get a copy of this message
At 2:53 PM -0700 10/2/09, Ben Dunlap wrote:
    $a = 2;
    $a = $a++;
    echo $a;
Honestly I think the only reason anyone would write an expression like that is either to fake out the compiler or because they don't properly understand the use of a unary operator. Or rather, of the increment/decrement operators, because no other unary operator actually changes the thing it operates on (AFAIK), which makes ++ and -- doubly weird. Ben
Honestly, I think that the only reason why one would write that is that they don't know any better. Why do this:
    $a = $a++;
when
    $a++;
will do what is intended? Cheers, tedd -- ------- http://sperling.com http://ancientstones.com http://earthstones.com

« previous php.general (#298526) next »