ID:               33360
 Updated by:       [EMAIL PROTECTED]
 Reported By:      luca dot fabbro at procne dot it
-Status:           Open
+Status:           Bogus
 Bug Type:         Session related
 Operating System: Linux
 PHP Version:      4.3.10
 New Comment:

With "$pointer = &$_SESSION['storage'][$i];" you turn
$_SESSION['storage'][$i]; into a reference.
But:
"Note: If array with references is copied, its values are not
dereferenced. This is valid also for arrays passed by value to
functions."
http://www.php.net/manual/en/language.references.whatdo.php
This is also has nothing to do with _SESSION as it can be reproduce on
this code too:

<?php
$a['storage'][] = array('items'=> 0);
$pointer = &$a['storage'][0];
$gitems = $a['storage'];
$gitems[0]['foo'] = 2;

var_dump($a);
?>


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

[2005-06-16 12:35:02] luca dot fabbro at procne dot it

Description:
------------
Seems that once you've declared a pointer to one of the items in
session superglobal any other assignment of a variable to that session
item is alwayys treated as a pointer.

Tested on various versions of php 4.3 till 4.3.1
Register globals are OFF
php 5.0.4 having same error


Reproduce code:
---------------
session_start();
for ($i = 0; $i < 2; $i++)
{
        $_SESSION['storage'][$i] = array('items'=>$i);
}
$items = count($_SESSION['storage']);
for ($i = 0; $i < $items; $i++)
{
        $pointer = &$_SESSION['storage'][$i];
//      unset($pointer);        // Uncomment me to let me work properly
}
$gitems = $_SESSION['storage'];
foreach ($gitems as $key=>$val)
{
        $gitems[$key]['foo'] = time();
}


Expected result:
----------------
$_SESSION = Array
(
    [storage] => Array
        (
            [0] => Array
                (
                    [items] => 0
                )
            [1] => Array
                (
                    [items] => 1
                )
        )
)

Actual result:
--------------
$_SESSION = Array
(
    [storage] => Array
        (
            [0] => Array
                (
                    [items] => 0
                    [foo] => 1118913576
                )

            [1] => Array
                (
                    [items] => 1
                    [foo] => 1118913576
                )
        )
)


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


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

Reply via email to