Re: A really wacky design decision

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



At 1:37 PM -0400 10/3/09, Robert Cummings wrote:
tedd wrote:
At 9:21 PM +1000 10/3/09, clancy_1@xxxxxxxxxxxx wrote:
Daevid Vincent is surprised that:

$num = 123;
$num = $num++;
print $num;  //this prints 123 and not 124 ?!!

I can understand why someone might think this is not correct, but they need to understand what is happening and why the above second assignment statement is in bad form (IMO).

The first statement assigns 123 to $num. Everyone is OK with that.
The next statement assigns 123 to $num, but then tries to increment $num, but doesn't because the assignment overrides the ++ operator -- this is bad form (IMO).

While I absolutely agree that it is bad form, I think you got the actual flow wrong. I think the $num++ copies the current value of $num, then increments $num to 124, then the previously copied value is returned at which point the assignment operator receives it and then overwrites the 124 with the copy of 123.

Cheers,
Rob.
--

Rob:

That could very well be -- I really don't know the flow. That was my best guess and what made sense to me.

Cheers,

tedd
--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux