FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » simple session question
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: OT: and even in Dart .........Re: simple session question [message #175746 is a reply to message #175743] Sun, 23 October 2011 03:05 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 10/22/2011 10:40 PM, Norman Peelman wrote:
> On 10/22/2011 04:28 PM, Jerry Stuckle wrote:
>> On 10/22/2011 4:08 PM, Norman Peelman wrote:
>>> On 10/22/2011 01:34 PM, Thomas Mlynarczyk wrote:
>>>> Luuk schrieb:
>>>> > i did send a bug-report:
>>>> > https://bugs.php.net/bug.php?id=60114
>>>>
>>>> I do not see any bug here. I was confused because it's a crappy way to
>>>> code, but it's clear why it works the way it does:
>>>>
>>>> $foo = 0;
>>>> $foo = $foo++;
>>>>
>>>> is definitely identical to
>>>>
>>>> $foo = 0;
>>>> $foo = ($foo++);
>>>>
>>>> since ++ has higher precedence than =. In fact, ($foo = $foo)++ does
>>>> rightfully throw a parse error, since you can only increment a
>>>> variable,
>>>> not an expression.
>>>>
>>>> As mentioned before in this thread, the above code is equivalent to
>>>>
>>>> $foo = 0;
>>>> $tmp = $foo; // $foo++ yields the previous value, which is 0
>>>> $foo = $foo + 1; // then $foo is incremented...
>>>> $foo = $tmp; // ...and then re-assigned the old value
>>>>
>>>> It's the exact same procedure as it would be with $foo = $bar++.
>>>>
>>>> Greetings,
>>>> Thomas
>>>>
>>>
>>> No they are not the same.
>>>
>>> $foo = 0;
>>> $foo = $foo++;
>>>
>>> It should be equivalent to:
>>>
>>> $foo = 0; // 0
>>> $foo = $foo; // 0 = 0
>>> $foo = $foo + 1; // 0 = (0 + 1)
>>>
>>> $foo++ means that the variable is to be incremented after the variable
>>> is accessed. Something is clobbering that increment.
>>>
>>> ++$foo means that the variable is to be incremented piror to the
>>> variable being accessed. Works as expected.
>>>
>>>
>>> Haven't seen the source code but there must be some temporary variable
>>> that's getting clobbered for the $foo++ example.
>>>
>>>
>>
>> Actually, I take my previous statement about the behavior being defined
>> back. Officially in C/C++, the results of this operation is undefined.
>>
>> Precedence and associativity define the order in which operators are
>> processed. But the order of operand processing is not defined.
>>
>> For
>>
>> $foo = $foo++;
>>
>> we have the same operand ($foo) being set twice. The $foo++ will return
>> 0, and this value will be assigned into $foo.
>>
>> But what is NOT defined is whether the assignment will occur before or
>> after the value of $foo is actually incremented. Either is possible.
>>
>> Now in the case of
>>
>> $foo = ($foo++);
>>
>> The results are different, but they are still undefined.
>>
>> In the first case the increment is obviously performed before the
>> assignment (although the assignment correctly uses the pre-increment
>> value).
>>
>> In the second case it looks like the assignment is still using the
>> pre-increment value, but the increment is done after the assignment.
>>
>> Since the results are undefined, both are correct (or incorrect, as you
>> may look at it), and may change with changes to the interpreter (or
>> potentially the same version on different OS's).
>>
>
> The problem seems to be that the post increment is being overwritten as if:
>
> $foo = 0;
> $tmp = $foo;
> $foo = $foo + 1;
> $foo = $tmp;
>
> Which I think someone else may have said.
>

It's not being "overwritten" - the operand is being changed twice in the
same expression, which is undefined in C.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: session cookie: client side
Next Topic: by get this format my explode file name like this through php
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Tue Dec 24 03:37:17 GMT 2024

Total time taken to generate the page: 0.04367 seconds