Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #3476 > unrolled thread

simple session question

Started bycerr <ron.eggler@gmail.com>
First post2011-10-21 10:44 -0700
Last post2011-10-23 15:47 +0000
Articles 20 on this page of 63 — 11 participants

Back to article view | Back to comp.lang.php


Contents

  simple session question cerr <ron.eggler@gmail.com> - 2011-10-21 10:44 -0700
    Re: simple session question Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2011-10-21 20:19 +0200
      Re: simple session question Jonathan Stein <jstein@image.dk> - 2011-10-21 20:51 +0200
        Re: simple session question Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2011-10-21 22:00 +0200
          Re: simple session question Jerry Stuckle <jstucklex@attglobal.net> - 2011-10-21 16:14 -0400
            Re: simple session question Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2011-10-22 00:50 +0200
              Re: simple session question Jerry Stuckle <jstucklex@attglobal.net> - 2011-10-21 19:05 -0400
                Re: simple session question Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2011-10-22 15:40 +0200
                  Re: simple session question Richard Damon <news.x.richarddamon@xoxy.net> - 2011-10-22 17:19 -0400
                    Re: simple session question The Natural Philosopher <tnp@invalid.invalid> - 2011-10-22 22:56 +0100
                      Re: simple session question Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2011-10-23 00:35 +0200
                      Re: simple session question Tim Streater <timstreater@greenbee.net> - 2011-10-22 23:43 +0100
                        Re: simple session question Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2011-10-23 01:56 +0200
                      Re: simple session question Richard Damon <news.x.richarddamon@xoxy.net> - 2011-10-22 19:29 -0400
                        Re: simple session question Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2011-10-23 01:54 +0200
                    Re: simple session question Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2011-10-23 02:12 +0200
                      Re: simple session question Richard Damon <news.x.richarddamon@xoxy.net> - 2011-10-22 21:13 -0400
                        Re: simple session question The Natural Philosopher <tnp@invalid.invalid> - 2011-10-23 08:44 +0100
                          Re: simple session question Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2011-10-23 17:31 +0200
                            Re: simple session question The Natural Philosopher <tnp@invalid.invalid> - 2011-10-23 17:18 +0100
                              Re: simple session question Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2011-10-23 19:14 +0200
                                Re: simple session question The Natural Philosopher <tnp@invalid.invalid> - 2011-10-23 18:16 +0100
                        Re: simple session question Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2011-10-23 19:00 +0200
                          Re: simple session question Richard Damon <news.x.richarddamon@xoxy.net> - 2011-10-23 15:28 -0400
                      Re: simple session question Jerry Stuckle <jstucklex@attglobal.net> - 2011-10-22 23:03 -0400
                        Re: simple session question Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2011-10-23 19:06 +0200
                          Re: simple session question Jerry Stuckle <jstucklex@attglobal.net> - 2011-10-23 14:35 -0400
              Re: simple session question The Natural Philosopher <tnp@invalid.invalid> - 2011-10-22 00:32 +0100
                Re: simple session question Luuk <Luuk@invalid.lan> - 2011-10-22 12:01 +0200
                  Re: simple session question The Natural Philosopher <tnp@invalid.invalid> - 2011-10-22 15:27 +0100
                    Re: simple session question The Natural Philosopher <tnp@invalid.invalid> - 2011-10-22 15:37 +0100
                      Re: simple session question Luuk <Luuk@invalid.lan> - 2011-10-22 17:08 +0200
                        OT: and even in Dart .........Re: simple session question Luuk <Luuk@invalid.lan> - 2011-10-22 17:17 +0200
                          Re: OT: and even in Dart .........Re: simple session question The Natural Philosopher <tnp@invalid.invalid> - 2011-10-22 16:54 +0100
                            Re: OT: and even in Dart .........Re: simple session question Luuk <Luuk@invalid.lan> - 2011-10-22 18:47 +0200
                              Re: OT: and even in Dart .........Re: simple session question Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2011-10-22 19:34 +0200
                                Re: OT: and even in Dart .........Re: simple session question Norman Peelman <npeelmandog@cfl.rr.com> - 2011-10-22 16:08 -0400
                                  Re: OT: and even in Dart .........Re: simple session question Jerry Stuckle <jstucklex@attglobal.net> - 2011-10-22 16:28 -0400
                                    Re: OT: and even in Dart .........Re: simple session question Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2011-10-23 01:39 +0200
                                    Re: OT: and even in Dart .........Re: simple session question Norman Peelman <npeelmandog@cfl.rr.com> - 2011-10-22 22:40 -0400
                                      Re: OT: and even in Dart .........Re: simple session question Jerry Stuckle <jstucklex@attglobal.net> - 2011-10-22 23:05 -0400
                                  Re: OT: and even in Dart .........Re: simple session question The Natural Philosopher <tnp@invalid.invalid> - 2011-10-22 22:52 +0100
                                    Re: OT: and even in Dart .........Re: simple session question Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2011-10-23 01:25 +0200
                                      Re: OT: and even in Dart .........Re: simple session question The Natural Philosopher <tnp@invalid.invalid> - 2011-10-23 08:41 +0100
                                  Re: OT: and even in Dart .........Re: simple session question Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2011-10-23 00:56 +0200
                                    Re: OT: and even in Dart .........Re: simple session question Norman Peelman <npeelmandog@cfl.rr.com> - 2011-10-22 22:52 -0400
                                      Re: OT: and even in Dart .........Re: simple session question Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2011-10-23 17:12 +0200
                                    Re: OT: and even in Dart .........Re: simple session question Tim Streater <timstreater@greenbee.net> - 2011-10-23 09:39 +0100
                                      Re: OT: and even in Dart .........Re: simple session question The Natural Philosopher <tnp@invalid.invalid> - 2011-10-23 09:40 +0100
                                        Re: OT: and even in Dart .........Re: simple session question Tim Streater <timstreater@greenbee.net> - 2011-10-23 09:43 +0100
                                  Re: OT: and even in Dart .........Re: simple session question "Peter H. Coffin" <hellsop@ninehells.com> - 2011-11-05 15:04 -0500
                                Re: OT: and even in Dart .........Re: simple session question The Natural Philosopher <tnp@invalid.invalid> - 2011-10-22 22:47 +0100
                                  Re: OT: and even in Dart .........Re: simple session question Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2011-10-23 01:22 +0200
                                    Re: OT: and even in Dart .........Re: simple session question The Natural Philosopher <tnp@invalid.invalid> - 2011-10-23 08:40 +0100
                                      Re: OT: and even in Dart .........Re: simple session question Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2011-10-23 17:04 +0200
                            Re: OT: and even in Dart .........Re: simple session question "Peter H. Coffin" <hellsop@ninehells.com> - 2011-11-05 15:00 -0500
                Re: simple session question Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2011-10-22 15:39 +0200
      Re: simple session question cerr <ron.eggler@gmail.com> - 2011-10-21 14:43 -0700
        Re: simple session question Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2011-10-22 00:47 +0200
        Re: simple session question Jerry Stuckle <jstucklex@attglobal.net> - 2011-10-21 19:06 -0400
      Re: simple session question cerr <ron.eggler@gmail.com> - 2011-10-21 14:17 -0700
        Re: simple session question Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2011-10-22 15:50 +0200
      Re: simple session question Denis McMahon <denismfmcmahon@gmail.com> - 2011-10-23 15:47 +0000

Page 3 of 4 — ← Prev page 1 2 [3] 4  Next page →


#3527 — Re: OT: and even in Dart .........Re: simple session question

FromJerry Stuckle <jstucklex@attglobal.net>
Date2011-10-22 23:05 -0400
SubjectRe: OT: and even in Dart .........Re: simple session question
Message-ID<j8009r$5j7$2@dont-email.me>
In reply to#3524
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@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#3511 — Re: OT: and even in Dart .........Re: simple session question

FromThe Natural Philosopher <tnp@invalid.invalid>
Date2011-10-22 22:52 +0100
SubjectRe: OT: and even in Dart .........Re: simple session question
Message-ID<j7vdvp$sjf$1@news.albasani.net>
In reply to#3505
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.
> 

No: increment is after assignment and the NEW value of foo is not being 
incremented.

Without the brackets $foo=$foo++ should mean an unchanged foo..thats 
perfectly legal.

Its the fact that the brackets don't force taking the value after 
increment that is worrisome


I.e.

$ php -r ' $foo=0; $bar=(($foo++)); print $bar."\n";'
0

[toc] | [prev] | [next] | [standalone]


#3517 — Re: OT: and even in Dart .........Re: simple session question

FromThomas Mlynarczyk <thomas@mlynarczyk-webdesign.de>
Date2011-10-23 01:25 +0200
SubjectRe: OT: and even in Dart .........Re: simple session question
Message-ID<j7vje7$6r3$2@news.albasani.net>
In reply to#3511
The Natural Philosopher schrieb:

> Its the fact that the brackets don't force taking the value after 
> increment that is worrisome

Brackets get evaluated first. Result is the old value (since it's a 
post-increment). Then, when all is done in the brackets (including the 
increment), there's a 0 waiting on the RHS to be assigned.

Greetings,
Thomas

-- 
Ce n'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!
(Coluche)

[toc] | [prev] | [next] | [standalone]


#3529 — Re: OT: and even in Dart .........Re: simple session question

FromThe Natural Philosopher <tnp@invalid.invalid>
Date2011-10-23 08:41 +0100
SubjectRe: OT: and even in Dart .........Re: simple session question
Message-ID<j80gfj$egr$4@news.albasani.net>
In reply to#3517
Thomas Mlynarczyk wrote:
> The Natural Philosopher schrieb:
> 
>> Its the fact that the brackets don't force taking the value after 
>> increment that is worrisome
> 
> Brackets get evaluated first. Result is the old value (since it's a 
> post-increment). Then, when all is done in the brackets (including the 
> increment), there's a 0 waiting on the RHS to be assigned.
> 

Not in C it aint.

> Greetings,
> Thomas
> 

[toc] | [prev] | [next] | [standalone]


#3515 — Re: OT: and even in Dart .........Re: simple session question

FromThomas Mlynarczyk <thomas@mlynarczyk-webdesign.de>
Date2011-10-23 00:56 +0200
SubjectRe: OT: and even in Dart .........Re: simple session question
Message-ID<j7vhmk$420$1@news.albasani.net>
In reply to#3505
Norman Peelman schrieb:

> $foo = 0;
> $foo = $foo++;
> 
> It should be equivalent to:
> 
> $foo = 0;        // 0
> $foo = $foo;     // 0 = 0
> $foo = $foo + 1; // 0 = (0 + 1)

No. What you are doing here is assigning first and then incrementing. 
The evaluation of $foo++ returns 0 and increments $foo as a side effect. 
This evaluation process must be completed before the assignment can happen:

[1] Evaluate the expression $foo++ (result: 0, side effect: $foo = 1)
[2] Assign the result to $foo ($foo = 0)

> $foo++ means that the variable is to be incremented after the variable 
> is accessed.

Yes, it means that the expression $foo++ evaluates to the value which 
$foo had before. And it is this value which is assigned to $foo after 
the $foo++ step is completed.

Greetings,
Thomas


-- 
Ce n'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!
(Coluche)

[toc] | [prev] | [next] | [standalone]


#3525 — Re: OT: and even in Dart .........Re: simple session question

FromNorman Peelman <npeelmandog@cfl.rr.com>
Date2011-10-22 22:52 -0400
SubjectRe: OT: and even in Dart .........Re: simple session question
Message-ID<j7vvhv$40d$1@dont-email.me>
In reply to#3515
On 10/22/2011 06:56 PM, Thomas Mlynarczyk wrote:
> Norman Peelman schrieb:
>
>> $foo = 0;
>> $foo = $foo++;
>>
>> It should be equivalent to:
>>
>> $foo = 0; // 0
>> $foo = $foo; // 0 = 0
>> $foo = $foo + 1; // 0 = (0 + 1)
>
> No. What you are doing here is assigning first and then incrementing.
Yes

> The evaluation of $foo++ returns 0 and increments $foo as a side effect.
Yes

> This evaluation process must be completed before the assignment can happen:
Yes

>
> [1] Evaluate the expression $foo++ (result: 0, side effect: $foo = 1)
Yes

> [2] Assign the result to $foo ($foo = 0)

   But when you echo $foo on the next line it should equal 1. It's a 
race condition as 0 is held in a temporary buffer, $foo is incremented, 
and then $foo is assigned the temporary buffer. Thereby overwriting the 
increment.


>
>> $foo++ means that the variable is to be incremented after the variable
>> is accessed.
>
> Yes, it means that the expression $foo++ evaluates to the value which
> $foo had before. And it is this value which is assigned to $foo after
> the $foo++ step is completed.
>

Not really *before*, i'd say *current* value.

> Greetings,
> Thomas
>
>


-- 
Norman
Registered Linux user #461062
-Have you been to www.php.net yet?-

[toc] | [prev] | [next] | [standalone]


#3538 — Re: OT: and even in Dart .........Re: simple session question

FromThomas Mlynarczyk <thomas@mlynarczyk-webdesign.de>
Date2011-10-23 17:12 +0200
SubjectRe: OT: and even in Dart .........Re: simple session question
Message-ID<j81asq$otq$1@news.albasani.net>
In reply to#3525
Norman Peelman schrieb:
>> [1] Evaluate the expression $foo++ (result: 0, side effect: $foo = 1)
>> [2] Assign the result to $foo ($foo = 0)

> But when you echo $foo on the next line it should equal 1. It's a race
> condition as 0 is held in a temporary buffer, $foo is incremented, and 
> then $foo is assigned the temporary buffer. Thereby overwriting the 
> increment.

And thus, echoing $foo should print 0. The temporary buffer is 0 and in 
[2] $foo is assigned this value, "overwriting the increment" as you 
write correctly. So why do you say that a subsequent echo $foo should 
print 1? And in the above scenario there is no race condition involved. 
There must be a misunderstanding of what you wrote on my part here.

>> Yes, it means that the expression $foo++ evaluates to the value which
>> $foo had before. And it is this value which is assigned to $foo after
>> the $foo++ step is completed.

> Not really *before*, i'd say *current* value.

Yes.

Greetings,
Thomas

-- 
Ce n'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!
(Coluche)

[toc] | [prev] | [next] | [standalone]


#3531 — Re: OT: and even in Dart .........Re: simple session question

FromTim Streater <timstreater@greenbee.net>
Date2011-10-23 09:39 +0100
SubjectRe: OT: and even in Dart .........Re: simple session question
Message-ID<timstreater-73160E.09394423102011@news.individual.net>
In reply to#3515
In article <j7vhmk$420$1@news.albasani.net>,
 Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> wrote:

> Norman Peelman schrieb:
> 
> > $foo = 0;
> > $foo = $foo++;
> > 
> > It should be equivalent to:
> > 
> > $foo = 0;        // 0
> > $foo = $foo;     // 0 = 0
> > $foo = $foo + 1; // 0 = (0 + 1)
> 
> No. What you are doing here is assigning first and then incrementing. 
> The evaluation of $foo++ returns 0 and increments $foo as a side effect. 
> This evaluation process must be completed before the assignment can happen:
> 
> [1] Evaluate the expression $foo++ (result: 0, side effect: $foo = 1)
> [2] Assign the result to $foo ($foo = 0)
> 
> > $foo++ means that the variable is to be incremented after the variable 
> > is accessed.
> 
> Yes, it means that the expression $foo++ evaluates to the value which 
> $foo had before. And it is this value which is assigned to $foo after 
> the $foo++ step is completed.

Yes - as per my JavaScript example. If I say:

   results[i++];

I get the value of results[i]. That value is held in limbo to be 
assigned to the LHS. Then the post-increment occurs. Then the result 
from limbo is assigned to LHS.

And so with PHP. Which will mean that:

$foo = $foo++;
$foo = ($foo++);

both act the same and set $foo to 0.

-- 
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted"  --  Bill of Rights 1689

[toc] | [prev] | [next] | [standalone]


#3532 — Re: OT: and even in Dart .........Re: simple session question

FromThe Natural Philosopher <tnp@invalid.invalid>
Date2011-10-23 09:40 +0100
SubjectRe: OT: and even in Dart .........Re: simple session question
Message-ID<j80juf$nct$1@news.albasani.net>
In reply to#3531
Tim Streater wrote:
> In article <j7vhmk$420$1@news.albasani.net>,
> Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> wrote:
> 
>> Norman Peelman schrieb:
>>
>> > $foo = 0;
>> > $foo = $foo++;
>> > > It should be equivalent to:
>> > > $foo = 0;        // 0
>> > $foo = $foo;     // 0 = 0
>> > $foo = $foo + 1; // 0 = (0 + 1)
>>
>> No. What you are doing here is assigning first and then incrementing. 
>> The evaluation of $foo++ returns 0 and increments $foo as a side 
>> effect. This evaluation process must be completed before the 
>> assignment can happen:
>>
>> [1] Evaluate the expression $foo++ (result: 0, side effect: $foo = 1)
>> [2] Assign the result to $foo ($foo = 0)
>>
>> > $foo++ means that the variable is to be incremented after the 
>> variable > is accessed.
>>
>> Yes, it means that the expression $foo++ evaluates to the value which 
>> $foo had before. And it is this value which is assigned to $foo after 
>> the $foo++ step is completed.
> 
> Yes - as per my JavaScript example. If I say:
> 
>   results[i++];
> 
> I get the value of results[i]. That value is held in limbo to be 
> assigned to the LHS. Then the post-increment occurs. Then the result 
> from limbo is assigned to LHS.
> 
> And so with PHP. Which will mean that:
> 
> $foo = $foo++;
> $foo = ($foo++);
> 
> both act the same and set $foo to 0.
> 
First I heard that []===().....

[toc] | [prev] | [next] | [standalone]


#3533 — Re: OT: and even in Dart .........Re: simple session question

FromTim Streater <timstreater@greenbee.net>
Date2011-10-23 09:43 +0100
SubjectRe: OT: and even in Dart .........Re: simple session question
Message-ID<timstreater-B21864.09432723102011@news.individual.net>
In reply to#3532
In article <j80juf$nct$1@news.albasani.net>,
 The Natural Philosopher <tnp@invalid.invalid> wrote:

> Tim Streater wrote:
> > In article <j7vhmk$420$1@news.albasani.net>,
> > Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> wrote:
> > 
> >> Norman Peelman schrieb:
> >>
> >> > $foo = 0;
> >> > $foo = $foo++;
> >> > > It should be equivalent to:
> >> > > $foo = 0;        // 0
> >> > $foo = $foo;     // 0 = 0
> >> > $foo = $foo + 1; // 0 = (0 + 1)
> >>
> >> No. What you are doing here is assigning first and then incrementing. 
> >> The evaluation of $foo++ returns 0 and increments $foo as a side 
> >> effect. This evaluation process must be completed before the 
> >> assignment can happen:
> >>
> >> [1] Evaluate the expression $foo++ (result: 0, side effect: $foo = 1)
> >> [2] Assign the result to $foo ($foo = 0)
> >>
> >> > $foo++ means that the variable is to be incremented after the 
> >> variable > is accessed.
> >>
> >> Yes, it means that the expression $foo++ evaluates to the value which 
> >> $foo had before. And it is this value which is assigned to $foo after 
> >> the $foo++ step is completed.
> > 
> > Yes - as per my JavaScript example. If I say:
> > 
> >   results[i++];
> > 
> > I get the value of results[i]. That value is held in limbo to be 
> > assigned to the LHS. Then the post-increment occurs. Then the result 
> > from limbo is assigned to LHS.
> > 
> > And so with PHP. Which will mean that:
> > 
> > $foo = $foo++;
> > $foo = ($foo++);
> > 
> > both act the same and set $foo to 0.
> > 
> First I heard that []===().....

Come again?

-- 
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted"  --  Bill of Rights 1689

[toc] | [prev] | [next] | [standalone]


#3696 — Re: OT: and even in Dart .........Re: simple session question

From"Peter H. Coffin" <hellsop@ninehells.com>
Date2011-11-05 15:04 -0500
SubjectRe: OT: and even in Dart .........Re: simple session question
Message-ID<slrnjbb5ma.hbg.hellsop@nibelheim.ninehells.com>
In reply to#3505
On Sat, 22 Oct 2011 16:08:01 -0400, 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.

Yes. The ASSIGNMENT back to $foo is clobbering it. The increment happens
immediately after access, before the VALUE is passed back to the
assignment.

> ++$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.

It's just happening in the proper order. increment happens before
assignment, exactly per
http://php.net/manual/en/language.operators.precedence.php

The catch is that the assignment is destroying the increment, because
the variable access happened BEFORE the increment.

-- 
17. When I employ people as advisors, I will occasionally listen to 
   their advice.
        --Peter Anspach's list of things to do as an Evil Overlord

[toc] | [prev] | [next] | [standalone]


#3510 — Re: OT: and even in Dart .........Re: simple session question

FromThe Natural Philosopher <tnp@invalid.invalid>
Date2011-10-22 22:47 +0100
SubjectRe: OT: and even in Dart .........Re: simple session question
Message-ID<j7vdm6$s2v$1@news.albasani.net>
In reply to#3500
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++);

But it should NOT be. The brackets should force increment  BEFORE 
assignment.

As they do correctly in C.

I.er.
$foo Ok sop far

$foo++; // thats foo +1 when the dust settles although it as the 
instantaneous valiue of foo. The +++ is the last thing that ghapp[ens

($foo++); // is an atomic expression meaning increment foo. Its value is 
whatever the final final value of foo is.


> 
> 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.
> 

That's irrelevant.
<snip>
The point is that bracketing is supposed to absolutely ensure that 
nothing outside gets done till the inside is complete.

So $a=($foo++); should be the same as
$foo++;
$a=$foo;

[toc] | [prev] | [next] | [standalone]


#3516 — Re: OT: and even in Dart .........Re: simple session question

FromThomas Mlynarczyk <thomas@mlynarczyk-webdesign.de>
Date2011-10-23 01:22 +0200
SubjectRe: OT: and even in Dart .........Re: simple session question
Message-ID<j7vj83$6r3$1@news.albasani.net>
In reply to#3510
The Natural Philosopher schrieb:

> The point is that bracketing is supposed to absolutely ensure that 
> nothing outside gets done till the inside is complete.

And that's exactly what happens:

// $foo = 0;
[1] Evaluate 0  // result: 0
[2] Assign result of [1] to $foo  // $foo = 0
// $foo = ($foo++);
[3] Evaluate operation "post-increment" on $foo  // ($foo++)
     [3.1] Set return value to current $foo  // result: 0
     [3.2] Add 1 to $foo  // $foo = 1
     [3.3] Return result  // 0
[4] Assign result of [3] to $foo  // $foo = 0

Thus, for a few nanoseconds, $foo is indeed 1, until this increment is 
undone in [4] by reassigning $foo its old value.

> So $a=($foo++); should be the same as
> $foo++;
> $a=$foo;

No. That would be $a = ++$foo.

Greetings,
Thomas

-- 
Ce n'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!
(Coluche)

[toc] | [prev] | [next] | [standalone]


#3528 — Re: OT: and even in Dart .........Re: simple session question

FromThe Natural Philosopher <tnp@invalid.invalid>
Date2011-10-23 08:40 +0100
SubjectRe: OT: and even in Dart .........Re: simple session question
Message-ID<j80ge9$egr$3@news.albasani.net>
In reply to#3516
Thomas Mlynarczyk wrote:
> The Natural Philosopher schrieb:
> 
>> The point is that bracketing is supposed to absolutely ensure that 
>> nothing outside gets done till the inside is complete.
> 
> And that's exactly what happens:
> 
> // $foo = 0;
> [1] Evaluate 0  // result: 0
> [2] Assign result of [1] to $foo  // $foo = 0
> // $foo = ($foo++);
> [3] Evaluate operation "post-increment" on $foo  // ($foo++)
>     [3.1] Set return value to current $foo  // result: 0

Why would one do that..what 'return value' is that...

You are making the side effect of lower precedence than the bracket. 
That is NEVER done.


>     [3.2] Add 1 to $foo  // $foo = 1
>     [3.3] Return result  // 0
> [4] Assign result of [3] to $foo  // $foo = 0
> 
> Thus, for a few nanoseconds, $foo is indeed 1, until this increment is 
> undone in [4] by reassigning $foo its old value.
> 
>> So $a=($foo++); should be the same as
>> $foo++;
>> $a=$foo;
> 
> No. That would be $a = ++$foo.
> 
> Greetings,
> Thomas
> 

[toc] | [prev] | [next] | [standalone]


#3537 — Re: OT: and even in Dart .........Re: simple session question

FromThomas Mlynarczyk <thomas@mlynarczyk-webdesign.de>
Date2011-10-23 17:04 +0200
SubjectRe: OT: and even in Dart .........Re: simple session question
Message-ID<j81adp$npt$1@news.albasani.net>
In reply to#3528
The Natural Philosopher schrieb:
>> // $foo = 0;
>> [1] Evaluate 0  // result: 0
>> [2] Assign result of [1] to $foo  // $foo = 0
>> // $foo = ($foo++);
>> [3] Evaluate operation "post-increment" on $foo  // ($foo++)
>>     [3.1] Set return value to current $foo  // result: 0

> Why would one do that..what 'return value' is that...

It's the result of evaluating the expression $foo++. It must remember 
the current value of $foo since that is what will be needed later. Why 
"one" would do that? Well, PHP needs to evaluate $foo++ somehow, how 
else is it supposed to work? The above algorithm is what PHP probably 
does under the hood in order to produce the observed behaviour.

> You are making the side effect of lower precedence than the bracket. 

No I'm not. With the above algorithm, the side effect happens well 
inside the brackets, i.e. within the evaluation of $oo++ -- that's step 
[3.2] below: increment $foo while still inside the evaluation routine 
[3]. At that moment, $foo = 1 and "the brackets are done", returning the 
evaluation result 0 in step [3.3].

> That is NEVER done.

My sketched algorithm does produce the observed result and is consistent 
with the aforementioned user comment in the PHP manual.

>>     [3.2] Add 1 to $foo  // $foo = 1
>>     [3.3] Return result  // 0
>> [4] Assign result of [3] to $foo  // $foo = 0

Greetings,
Thomas

-- 
Ce n'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!
(Coluche)

[toc] | [prev] | [next] | [standalone]


#3695 — Re: OT: and even in Dart .........Re: simple session question

From"Peter H. Coffin" <hellsop@ninehells.com>
Date2011-11-05 15:00 -0500
SubjectRe: OT: and even in Dart .........Re: simple session question
Message-ID<slrnjbb5ed.hbg.hellsop@nibelheim.ninehells.com>
In reply to#3496
On Sat, 22 Oct 2011 16:54:11 +0100, The Natural Philosopher wrote:
> Luuk wrote:
>> On 22-10-2011 17:08, Luuk wrote:
>>> On 22-10-2011 16:37, The Natural Philosopher wrote:
>>>> The Natural Philosopher wrote:
>>>>> Luuk wrote:
>>>>>> On 22-10-2011 01:32, The Natural Philosopher wrote:
>>>>>>> try $foo=($foo++);
>>>>>>>
>>>>>>> But actually, why not just
>>>>>>>
>>>>>>> $foo+=1;
>>>>>>
>>>>>> Because they differ?
>>>>>>
>>>>>> $ php -r ' $foo=0; $foo=$foo++; print $foo."\n";'
>>>>>> 0
>>>>>> $ php -r ' $foo=0; $foo=($foo++); print $foo."\n";'
>>>>>> 0
>>>>>
>>>>> That is surely a bug..
>>>>>
>>>>
>>>> viz
>>>>
>>>> ~$ cat test.c
>>>> #include <stdio.h>
>>>> main()
>>>> {
>>>> int foo;
>>>> foo=0;
>>>> foo=(foo++);
>>>> printf("%d\n",foo);
>>>> }
>>>> ~$ ./test
>>>> 1
>>>>
>>>>
>>>> I thought PHP followed C operator precedence exactly..
>>>>
>>>>
>>>
>>> it seems to follow PERL
>>>
>>> $ perl -e '$foo=0; $foo=$foo++; print $foo."\n";'
>>> 0
>>> $ perl -e '$foo=0; $foo=($foo++); print $foo."\n";'
>>> 0
>>> $ perl -e '$foo=0; $foo++; print $foo."\n";'
>>> 1
>>> $
>>>
>>>
>> 
>> see: http://www.dartlang.org
>> 
>> main() {
>>   int foo=0;
>>   foo=foo++;
>>   print('First test: ${foo}');
>> 
>>   foo=0;
>>   foo=(foo++);
>>   print('Second test: ${foo}');
>> 
>>   foo=0;
>>   foo++;
>>   print('Third test: ${foo}');
>> 
>> }
>> 
>> which gives:
>> First test: 0
>> Second test: 0
>> Third test: 1
>> 
>> 
>
> still a bug in PHP where
>
> "Parentheses may be used to force precedence, if necessary. For 
> instance: (1 + 5) * 3 evaluates to 18"
>
> (from the manual)
>
> I THOUGHT the general rule was that the value of (entity) was always the 
> FINAL value after ALL internal operations had been carried out.
>
> Agreed its a crappy way to code, which is probably why no one has 
> noticed it.

The thing is that PHP is doing the right thing there. Remember that 

$foo++

is not the same as 

++$foo

The former "returns" the value PRIOR to incrementing, the latter AFTER
incrementing. Even wrapping $foo++ in parens won't change what it
returns. Don't use one when you want the other.

-- 
93. If I decide to hold a double execution of the hero and an underling
    who failed or betrayed me, I will see to it that the hero is 
    scheduled to go first.
	--Peter Anspach's list of things to do as an Evil Overlord

[toc] | [prev] | [next] | [standalone]


#3489

FromThomas Mlynarczyk <thomas@mlynarczyk-webdesign.de>
Date2011-10-22 15:39 +0200
Message-ID<j7uh27$rvt$1@news.albasani.net>
In reply to#3487
The Natural Philosopher schrieb:

> try $foo=($foo++);
> 
> But actually, why not just
> 
> $foo+=1;

Well, as Luuk mentioned, they are not the same. And I almost never use 
the increment/decrement operators. I prefer the form $foo += 1. What I 
find confusing about $foo = $foo++ is that it is not intuitively clear 
what it does. The OP had certainly intended "$foo++" (just increment 
$foo), but PHP interprets the construct differently. In a way which 
makes sense when you think about it, but which was not obvious to me 
from the start. And I am still not sure that there is no optimizer or 
similar extension that would optimize this construct to a simple $foo++.

Greetings,
Thomas


-- 
Ce n'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!
(Coluche)

[toc] | [prev] | [next] | [standalone]


#3481

Fromcerr <ron.eggler@gmail.com>
Date2011-10-21 14:43 -0700
Message-ID<5214a71c-144c-405d-945e-06d9c67473e1@v33g2000prm.googlegroups.com>
In reply to#3477
On Oct 21, 11:19 am, Thomas Mlynarczyk <tho...@mlynarczyk-
webdesign.de> wrote:
> cerr schrieb:
>
> > if(!isset($_SESSION['stp'])) {
> >   session_start();
> >   $_SESSION['stp'] = 0;
> >   echo "session started<br>\n";
> > }
>
> You need to call session_start() on *every* page request, not just when
> you initialize the session (think of it as
> "session_start_or_continue()"). The $_SESSION superglobal does not exist
> until you have called session_start(), so your code above won't work.
>
> > switch($_SESSION['stp']) {
> >   case 0: $_SESSION['stp'] = $_SESSION['stp']++;
> >              echo "stp:".$_SESSION['stp'];
> >              break;
> >   case 1: $_SESSION['stp'] = $_SESSION['stp']++;
> >              echo "stp:".$_SESSION['stp'];
> >              break;
> >   case 2: $_SESSION['stp'] = $_SESSION['stp']++;
> >              echo "stp:".$_SESSION['stp'];
> >           $_SESSION['stp'] = 0;
> >              break;
>
> You're missing a } here. But even with that and the session_start()
> issue fixed, it always prints 0. I'm not quite sure why, but anyway your
> code is unnecessarily complicated. Here's my version:
>
> session_start();
> if ( !isset( $_SESSION['stp'] ) )
> {
>      $_SESSION['stp'] = 0;
>      echo "session started<br>\n";
>
> }
>
> echo $_SESSION['stp'];
> $_SESSION['stp'] = ( $_SESSION['stp'] + 1 ) % 3;
>
> I use the modulo operator % to achieve the cycling through the values 0,
> 1, 2.
>

Weird, my phpinfo() says: "Session Support	enabled"
but even with code like this
<?php
session_start();
echo ++$_SESSION['test'];
?>
just prints "session_start(); 1" - and i'm wondering why it's printing
session_start(); in the browser, seems like it doesn't know this
command...? Weird, any clues...?

Thanks alot!
Ron

[toc] | [prev] | [next] | [standalone]


#3482

FromThomas Mlynarczyk <thomas@mlynarczyk-webdesign.de>
Date2011-10-22 00:47 +0200
Message-ID<j7sspo$a7e$1@news.albasani.net>
In reply to#3481
cerr schrieb:
> Weird, my phpinfo() says: "Session Support	enabled"
> but even with code like this
> <?php
> session_start();
> echo ++$_SESSION['test'];
> ?>
> just prints "session_start(); 1" - and i'm wondering why it's printing
> session_start(); in the browser, seems like it doesn't know this
> command...? Weird, any clues...?

Strange. Here it works. (Except for the notice about the undefined index 
'test' at the first call, but that is easily fixed and has nothing to do 
with the problem.) If your PHP installation did not know the 
session_start() function it would give you a fatal error. Is your above 
code the exact same code (copy & paste) you were running?

Greetings,
Thomas

-- 
Ce n'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!
(Coluche)

[toc] | [prev] | [next] | [standalone]


#3485

FromJerry Stuckle <jstucklex@attglobal.net>
Date2011-10-21 19:06 -0400
Message-ID<j7stu9$4k0$2@dont-email.me>
In reply to#3481
On 10/21/2011 5:43 PM, h wrote:
> On Oct 21, 11:19 am, Thomas Mlynarczyk<tho...@mlynarczyk-
> webdesign.de>  wrote:
>> cerr schrieb:
>>
>>> if(!isset($_SESSION['stp'])) {
>>>    session_start();
>>>    $_SESSION['stp'] = 0;
>>>    echo "session started<br>\n";
>>> }
>>
>> You need to call session_start() on *every* page request, not just when
>> you initialize the session (think of it as
>> "session_start_or_continue()"). The $_SESSION superglobal does not exist
>> until you have called session_start(), so your code above won't work.
>>
>>> switch($_SESSION['stp']) {
>>>    case 0: $_SESSION['stp'] = $_SESSION['stp']++;
>>>               echo "stp:".$_SESSION['stp'];
>>>               break;
>>>    case 1: $_SESSION['stp'] = $_SESSION['stp']++;
>>>               echo "stp:".$_SESSION['stp'];
>>>               break;
>>>    case 2: $_SESSION['stp'] = $_SESSION['stp']++;
>>>               echo "stp:".$_SESSION['stp'];
>>>            $_SESSION['stp'] = 0;
>>>               break;
>>
>> You're missing a } here. But even with that and the session_start()
>> issue fixed, it always prints 0. I'm not quite sure why, but anyway your
>> code is unnecessarily complicated. Here's my version:
>>
>> session_start();
>> if ( !isset( $_SESSION['stp'] ) )
>> {
>>       $_SESSION['stp'] = 0;
>>       echo "session started<br>\n";
>>
>> }
>>
>> echo $_SESSION['stp'];
>> $_SESSION['stp'] = ( $_SESSION['stp'] + 1 ) % 3;
>>
>> I use the modulo operator % to achieve the cycling through the values 0,
>> 1, 2.
>>
>
> Weird, my phpinfo() says: "Session Support	enabled"
> but even with code like this
> <?php
> session_start();
> echo ++$_SESSION['test'];
> ?>
> just prints "session_start(); 1" - and i'm wondering why it's printing
> session_start(); in the browser, seems like it doesn't know this
> command...? Weird, any clues...?
>
> Thanks alot!
> Ron

That's because the code you posted is not what you have in your script.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


Page 3 of 4 — ← Prev page 1 2 [3] 4  Next page →

Back to top | Article view | comp.lang.php


csiph-web