On 16 Aug 2008, at 13:20, tedd wrote:
At 12:40 PM +0100 8/16/08, Stut wrote:
On 16 Aug 2008, at 12:36, tedd wrote:
The problem here is can I use a variable within a $_SESSION[]
declaration?
Like so:
$_SESSION[$var]
I haven't really been following this thread but using a variable
like that is perfectly valid. $_SESSION is no different to any
other array during the processing of your script, the only
difference is that it's stored between requests.
-Stut
Stut:
I was hoping you would join in. But I solved the problem and found a
surprising result.
The result is you cannot use a number as an index in a $_SESSION,
like so:
$a = "20";
$_SESSION[$a] = "good morning'; <-- won't work
But you can use:
$a = "a20';
$_SESSION[$a] = "good night'; <-- will work
Furthermore, if you do make that mistake, all other $_SESSION
variables declared AFTER the incident will cease to work. Isn't that
interesting?
Here's an example:
http://www.webbytedd.com/b2/session-test1/index.php
The code is at the bottom of the page.
Please tell me that you didn't know this, for if you do, it will
make my day. On the other hand, if you tell me where I it wrong, it
will still make my day. :-)
Ahh, I see the problem. You've never been able to use numbers as keys
at the root level of the $_SESSION array. It's not a bug, it's just
the way it is. I've just checked the documentation and can't find an
obvious reference to this limitation which is kinda annoying.
I would question why you would want to do such a thing. Whenever I use
sessions (which is rare these days) I tend to organise the data with
some sort of context, which generally doesn't end up using pure numbers.
If you really want to use numeric indices in your session array you
can do so by adding a second level, i.e. $_SESSION['vars'] = array(20
=> 'good night');
-Stut
--
http://stut.net/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php