Reply to Re: "Array to String Conversion" error when constructing a multi-dimensional array

Your name:

Reply:


Posted by Rik on 01/18/07 12:50

drako wrote:


Don't fix bottom-posting, fix topposting.....

> Kimmo Laine wrote:
>> "drako" <neil@invidion.co.uk> wrote in message
>> news:1169067038.010143.224210@a75g2000cwd.googlegroups.com...
>>> 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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация