php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35511 Unserialized global arrays do not globalize in functions properly.
Submitted: 2005-12-01 20:51 UTC Modified: 2005-12-01 21:18 UTC
From: ngaugler at ngworld dot net Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.4.1 OS: Linux 2.6
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: ngaugler at ngworld dot net
New email:
PHP Version: OS:

 

 [2005-12-01 20:51 UTC] ngaugler at ngworld dot net
Description:
------------
In 4.4.1, when you unserialize an array, then attempt to globalize it within a function, and then pass it to an internal array function such as next or key, it does not work as it was in 4.3.10 or how it functions in PHP 5.0.5.  This functions as expected in 4.3.10 and 5.0.5.  The documentation clearly states you are not to use next(&array) or key(&array) when using references, which is why this is not used.

Reproduce code:
---------------
<?
$ar = array(array('ID' => 'BOB'),  array('ID' => 'GEORGE'),  array('ID' => 'JOHN'));

$ser = serialize($ar);
$arn = unserialize($ser);

print_r($arn) . "\n\n"; 

function breakPHP() {
    global $arn;
    for ($i = 0, reset($arn); ($key = key($arn)), (isset($key)); next($arn), $i++) { 
        print "$key ... " . $arn[$key]['ID'] . "<br>\n";
        if ($i > 5) {
            print "we looped";
            exit;   
        }       
    }
}
breakPHP();
?>

Expected result:
----------------
Array
(
    [0] => Array
        (
            [ID] => BOB
        )

    [1] => Array
        (
            [ID] => GEORGE
        )

    [2] => Array
        (
            [ID] => JOHN
        )

)
0 ... BOB<br>
1 ... GEORGE<br>
2 ... JOHN<br>

Actual result:
--------------
Array
(
    [0] => Array
        (
            [ID] => BOB
        )

    [1] => Array
        (
            [ID] => GEORGE
        )

    [2] => Array
        (
            [ID] => JOHN
        )

)
0 ... BOB<br>
0 ... BOB<br>
0 ... BOB<br>
0 ... BOB<br>
0 ... BOB<br>
0 ... BOB<br>
0 ... BOB<br>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-12-01 20:55 UTC] tony2001@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.

Fixed in CVS months ago.
 [2005-12-01 21:15 UTC] ngaugler at ngworld dot net
What is the link to the same bug?  I searched many times and was unable to locate one.
 [2005-12-01 21:18 UTC] ngaugler at ngworld dot net
I found it, had to change the wording to look more for next specific functions.
http://bugs.php.net/bug.php?id=35444
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 15:01:28 2024 UTC