Re: "Array to String Conversion" error when constructing a multi-dimensional array
- From: "Rik" <luiheidsgoeroe@xxxxxxxxxxx>
- Date: Thu, 18 Jan 2007 13:50:15 +0100
drako wrote:
Don't fix bottom-posting, fix topposting.....
Kimmo Laine wrote:
"drako" <neil@xxxxxxxxxxxxxx> wrote in message
news:1169067038.010143.224210@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
OK,
I inserted the debugging statements as you suggested:
$_SESSION["increment"] = array();
echo '1: ';print_r($_SESSION["increment"]);echo '<br>';
$x = 0 // Counter - This will be
incremented
echo '2: ';print_r($increment); echo '<br>';
I don't understand what this $increment variable has to do with
anything.
It doesn't actually relate to anything; but I suspect it was
suggested just to see if anything was output - and nothing was output.
I know if 'register_globals' is switched on, this could potentially
cause a problem, but in this case, globals is switched off, so is not
the problem.
I now suspect this is session-related in someway. As the code looks
OK, the problem arises from elsewhere....
Nope.
Keep in mind, that on strings, the [] will get or set the character of the
string at that particular location. My suspicion is that you don't give us
the real code (for where would the incrementation take place?), and you
turn the array into the string ( or number) '1' somewhere. (This often
happens when you use the return of a function (true) that works be a
reference instead of a return by accident.)
So, in the first loop, we've made $_SESSION["increment"] into a string by
accident. On the second loop, if $x = 1, that's the second position in the
string (which was not previously set). You try to set a character to an
array, so the array is converted to a string ('Array'), then it takes the
first character ('A') from that string, and put it at position 1. Hence
resulting in '1A'.
If you gave us the real code, I'd bet we'd spot where the actual overriding
on $_SESSION["increment"] takes place.
--
Rik Wasmus
.
- Follow-Ups:
- References:
- Prev by Date: Re: directly using an index on returned array
- Next by Date: Re: Best way to conditionally show large blocks of HTML
- Previous by thread: Re: "Array to String Conversion" error when constructing a multi-dimensional array
- Next by thread: Re: "Array to String Conversion" error when constructing a multi-dimensional array
- Index(es):