Re: SESSION problem
| From: | Sabine Richter | Date: | Sat, 16 Aug 2008 12:45:18 +0000 |
| Subject: | Re: SESSION problem | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-278222@lists.php.net to get a copy of this message | ||
Hello Tedd,
tedd schrieb:
At 2:09 PM +0200 8/16/08, Sabine Richter wrote:Yes, our mails overlaped each other (Do you say that in english? My english is not the best.)Hello Tedd, it seems to be a naming problem. You may not use a numeric value for a variable name to store in $_SESSION. By assigning it to $_SESSION, you get a Notice: Unknown: Skipping numeric key 1 in Unknown on line 0 and in your second script a Notice: Undefined offset: 1 in yourpath\index1.php on line XX -> whatever line it was in your script If you define $_SESSION['var'.$i] = $i; or $_SESSION[$i.'var'] = $i; or even $_SESSION[$i.'.1'] = $i; the $_SESSION won't forget your vars on the way to script 2. But it's a bit strange, that you can use your numeric keys in script 1. I tried with other Superglobals like $_POST and $_COOKIE and they seem to accept numeric variable names. So, is that a php bug? But as the docu says "A valid variable name starts with a letter or underscore", I think you can not complain about it. Cheers SabineSabine: You hit the nail right on the head. I discovered that fact this morning and posted an answer already. Here's the demo: http://www.webbytedd.com/b2/session-test1/index.php
I read everything I could find about sessions, but didn't come across: "A valid variable name starts with a letter or underscore" To the contrary, this is only what I found: Variable names follow the same rules as other labels in PHP. A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores Where did you see that?My citation is just a part of what you found. By the way: I tried your initial code and I had no problem with the variable declared after the numeric ones. (your $_SESSION['test']). I tried on a Version 5.2.5 an Win XP. Cheers, Sabine
Cheers, tedd