On 16 Aug 2008, at 14:46, tedd wrote:
At 2:11 PM +0100 8/16/08, Stut wrote:
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 agree.

But what I find even more annoying is:

1) No error is generated.

2) The error prohibits ALL other SESSION variables legally declared after the error to stop working!

In other words, if you make the mistake of using a numeric index for a SESSION, then ALL legal SESSIONs declared after that will stop working. And, what makes this even more frustrating is that ALL SESSIONs declared before will continue to work. IMO, it would be better if once you screwed it up, then everything would stop working.

So, let's say this happens (as it did to me last year), you have a set of scripts that work fine and in one script you use a numeric index for a SESSION. Once that statement is encountered in the flow of the program, ALL other SESSION variables declared after that don't work anymore.

In one sequence of scripts everything worked fine and in a different sequence only some things work. That was maddening and I never knew what it was until now. And, no mention of this problem in the documentation.

This should give you a bit more ammunition for your "I never use SESSIONs for anything" argument.

Not really, since I would never name a session variable 1, or 2, or 5318008 - I would always put those in the session in a named array.

--- you further stated

I would question why you would want to do such a thing.

You have never moved data between arrays?!? Come on, I'm sure you have done it before.

It's an old habit I have filling arrays -- I never had any problems using numbers before.

This works:

for ($i; $i<10; $i++)
  {
  $things[$i] = $other_things[$i];
  }

I was looking at SESSION the same way -- after all it IS called an array.

Let me play the age-card -- in every language I've programmed in for the last 43 years an array can have numeric indexes -- except php's SESSION.

I wish I understood the reason why it's like this but I've never looked into the session extension in that level of detail, but I doubt such a limitation would exist if there was not a very good reason for it. But again, I don't see how this is relevant.

It's natural to me to see the session array as a filing cabinet. At the top level you would have files with names that indicate what they are. Within each file it may be further divided into numbered sections. Given that I can't see into the future, even if I currently only have one set of data (file) to store in the session (the filing cabinet) I wouldn't just chuck the bits of paper from the file into the filing cabinet. I'd leave them in the file such that when I need to add a new file I don't need to gather up all the other bit of paper into a single file to get it organised again.

Ok, that didn't quite make it as clear as I wanted it to but I hope it illustrates the point I'm trying to make. The root level of the session array (IMHO) should contain descriptive keys, and I've never been in a situation where 5318008 is descriptive and gives context to the data unless you turn it upside down!

-Stut

--
http://stut.net/

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

Reply via email to