php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29932 Array Memory Allocation Error With register_globals set to "On"
Submitted: 2004-09-01 17:47 UTC Modified: 2004-09-16 01:00 UTC
From: joshua dot montgomery at middlebrow dot com Assigned:
Status: No Feedback Package: Scripting Engine problem
PHP Version: 4.3.8 OS: Debian
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: joshua dot montgomery at middlebrow dot com
New email:
PHP Version: OS:

 

 [2004-09-01 17:47 UTC] 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
)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-09-02 08:11 UTC] derick@php.net
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-02 18:47 UTC] 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-06 16:02 UTC] tony2001@php.net
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.
 [2004-09-16 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Tue Sep 27 14:05:52 2022 UTC