ID:               29932
 Updated by:       [EMAIL PROTECTED]
 Reported By:      joshua dot montgomery at middlebrow dot com
-Status:           Open
+Status:           Feedback
 Bug Type:         Scripting Engine problem
 Operating System: Debian
 PHP Version:      4.3.8
 New Comment:

Try to you unset $ArrayVariable's value before while{} - I bet you'll
get the expected result. This happens because with register_globals=On
$ArrayVariable gets extracted from SESSION, GET, POST or from other
sources.
Please supply _working, complete_ reproduce script next time.


Previous Comments:
------------------------------------------------------------------------

[2004-09-02 18:47:28] joshua dot montgomery at middlebrow dot com

I don't think I was clear enough last time.  This is indeed a PHP
problem.  The fix is turning register_globals off or explicitly setting
the array ahead of time.

A more concises way of stating the problem is:

When implicitly populating an array WITH an array, PHP is picking up
the FIRST LETTER of each element of the child array and populating the
parent array with a string.

Looks like a memory allocation issue to me.

------------------------------------------------------------------------

[2004-09-02 08:11:04] [EMAIL PROTECTED]

Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions. 

Thank you for your interest in PHP.

.

------------------------------------------------------------------------

[2004-09-01 17:47:00] joshua dot montgomery at middlebrow dot com

Description:
------------
We fixed this bug by setting Register_Globals to "Off", but we were
also making other changes on the server to solve it, so that might not
have been the fix.

We are using the following code to store database entries in memory for
use later on in the page

When allocating memory for an array dynamically using a sql_query the
values came out as strings, rather than arrays.

I took all of the error checking out of the code below to make it more
clear.  We use this code to dump an array to a select menu creation
function.

It should be noted that this bug doesn't always appear, but seems to be
produced for larger arrays (10 - 25) rather than arrays containing 2 or
3 entries.

It should also be noted that adding the statement "$ArrayVariable =
array()" before the following code also solves the problem.



Reproduce code:
---------------
$rslt = mysql_query("SQL....")
$i = 0;
while ($row = mysql_fetch_array($rslt)) {

$ArrayVariable[$i]['Value'] = $row['SQL_Text Value'];
$ArrayVariable[$i]['Label'] = $row['SQL_Text Label'];
$i++;

}

print_r($ArrayVariable);

Expected result:
----------------
Array
(
    [0] => Array
        (
            [Value] => 145
            [Label] => Adair, Kris
        )

    [1] => Array
        (
            [Value] => 20
            [Label] => Bailey, Wayne
        )

    [2] => Array
        (
            [Value] => 22
            [Label] => Bartos, Alan
        )

    [3] => Array
        (
            [Value] => 24
            [Label] => Beatty, Marsha
        )
)

Actual result:
--------------
Array
(
    [0] => 1A

    [1] => 2B

    [2] => 2B

    [3] => 2B
)


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=29932&edit=1

Reply via email to