ID:               47173
 User updated by:  tommyhp2 at yahoo dot com
 Reported By:      tommyhp2 at yahoo dot com
 Status:           Bogus
 Bug Type:         Session related
 Operating System: Win03 R2 SP2 PHP ISAPI
 PHP Version:      5.2.8
 New Comment:

I don't understand how is this bogus? I did look at the manual to make
sure I used the variable variables and reference correctly.  Looking at
the code give, if I pass string 'arr' to the function, then $$var ==
${'arr'}. There is no ambiguity.  If I do a var_dump($$var) equivalent
to var_dump(${'arr'}) inside the function right after global $$var, I
get the defined global $arr array contents.  I didn't see any where in
the manual at
http://www.php.net/manual/en/language.variables.variable.php
about not being able to use it or implement it inside a function since
the examples didn't implement inside a function.

As for references, I don't think it's used improperly. Since I could
have multiple references to a single value:
$a = 'some string';
$b =& $a;
$c =& $a;

echo $b; // gives 'some string'
echo $c; // gives 'some string'

$a = 'nada';
echo $b; // gives 'nada'

which those 2 concepts, this code

$arr = array('idx1'=>'val1','idx2'=>'val2','idx3'=>'val3');
if (isset($_SESSION['arr']))
{
        $arr =& $_SESSION['arr'];
} else {
        $_SESSION =& $arr;
}

works as intended. If put the if/else inside a function and replace
with the appropriate variable along with global definition, why does it
break with no reference?  Or is referencing not permitted inside a
function? Which I don't see in the manual. As for the example in the
manual of 
function foo(&$var)
{
    $var++;
}
I'm not passing the value or the pointer/reference.  I'm passing a
string and using the string via variable variables and global and
referencing it as variable variables.

Thanks,
Tommy


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

[2009-01-21 00:12:42] [email protected]

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Do not do that..

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

[2009-01-20 19:32:22] tommyhp2 at yahoo dot com

Same problem w/ CVS PHP 5.2 - Windows x86 VC6 (thread safe))  [10.02MB]
- 2009-Jan-20 12:00:00

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

[2009-01-20 19:27:31] tommyhp2 at yahoo dot com

Description:
------------
use of variable variables broken when reference inside a function in
conjunction with $_SESSION.

Thanks,
Tommy

Reproduce code:
---------------
Scenario 1:
<code>
session_start();

$arr = array('idx1'=>'val1','idx2'=>'val2','idx3'=>'val3');

if (isset($_SESSION['arr']))
{
        $arr =& $_SESSION['arr'];
} else {
        $_SESSION =& $arr;
}
</code>
Works as intended (please see "Expected result").

Scenario 2:
<code>
function register_session($var)
{
        global $$var;

        if (isset($_SESSION[$var]))
        {
                $$var =& $_SESSION[$var];
        } else
        {
                $_SESSION[$var] =& $$var;
        }
}

session_start();

$arr = array('idx1'=>'val1','idx2'=>'val2','idx3'=>'val3');
register_session('arr');
</code>
Does not work as intended (Please see "Actual result").  The variable
$arr is not referenced.

Expected result:
----------------
["_SESSION"]=>
  &array(3) {
    ["idx1"]=>
    string(4) "val1"
    ["idx2"]=>
    string(4) "val2"
    ["idx3"]=>
    string(4) "val3"
  }
  ["arr"]=>
  &array(3) {
    ["idx1"]=>
    string(4) "val1"
    ["idx2"]=>
    string(4) "val2"
    ["idx3"]=>
    string(4) "val3"
  }

Actual result:
--------------
["_SESSION"]=>
  &array(1) {
    ["arr"]=>
    array(3) {
      ["idx1"]=>
      string(4) "val1"
      ["idx2"]=>
      string(4) "val2"
      ["idx3"]=>
      string(4) "val3"
    }
  }
  ["arr"]=>
  array(3) {
    ["idx1"]=>
    string(4) "val1"
    ["idx2"]=>
    string(4) "val2"
    ["idx3"]=>
    string(4) "val3"
  }


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


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

Reply via email to